Chromium Code Reviews| 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 <algorithm> | 7 #include <algorithm> | 
| 8 #include <limits> | 8 #include <limits> | 
| 9 #include <set> | 9 #include <set> | 
| 10 #include <utility> | 10 #include <utility> | 
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 float page_scale_factor, | 157 float page_scale_factor, | 
| 158 float maximum_animation_contents_scale, | 158 float maximum_animation_contents_scale, | 
| 159 bool animating_transform_to_screen) { | 159 bool animating_transform_to_screen) { | 
| 160 layer->draw_properties().ideal_contents_scale = ideal_contents_scale; | 160 layer->draw_properties().ideal_contents_scale = ideal_contents_scale; | 
| 161 layer->draw_properties().device_scale_factor = device_scale_factor; | 161 layer->draw_properties().device_scale_factor = device_scale_factor; | 
| 162 layer->draw_properties().page_scale_factor = page_scale_factor; | 162 layer->draw_properties().page_scale_factor = page_scale_factor; | 
| 163 layer->draw_properties().maximum_animation_contents_scale = | 163 layer->draw_properties().maximum_animation_contents_scale = | 
| 164 maximum_animation_contents_scale; | 164 maximum_animation_contents_scale; | 
| 165 layer->draw_properties().screen_space_transform_is_animating = | 165 layer->draw_properties().screen_space_transform_is_animating = | 
| 166 animating_transform_to_screen; | 166 animating_transform_to_screen; | 
| 167 layer->UpdateTiles(Occlusion()); | 167 bool resourceless_software_draw = false; | 
| 168 layer->UpdateTiles(Occlusion(), resourceless_software_draw); | |
| 168 } | 169 } | 
| 169 static void VerifyAllTilesExistAndHavePile( | 170 static void VerifyAllTilesExistAndHavePile( | 
| 170 const PictureLayerTiling* tiling, | 171 const PictureLayerTiling* tiling, | 
| 171 PicturePileImpl* pile) { | 172 PicturePileImpl* pile) { | 
| 172 for (PictureLayerTiling::CoverageIterator iter( | 173 for (PictureLayerTiling::CoverageIterator iter( | 
| 173 tiling, | 174 tiling, | 
| 174 tiling->contents_scale(), | 175 tiling->contents_scale(), | 
| 175 gfx::Rect(tiling->tiling_size())); | 176 gfx::Rect(tiling->tiling_size())); | 
| 176 iter; | 177 iter; | 
| 177 ++iter) { | 178 ++iter) { | 
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 257 for (tile_iter = tiles.begin(); tile_iter < tiles.end(); tile_iter++) { | 258 for (tile_iter = tiles.begin(); tile_iter < tiles.end(); tile_iter++) { | 
| 258 MockCanvas mock_canvas(1000, 1000); | 259 MockCanvas mock_canvas(1000, 1000); | 
| 259 active_pile->RasterDirect( | 260 active_pile->RasterDirect( | 
| 260 &mock_canvas, (*tile_iter)->content_rect(), 1.0f, NULL); | 261 &mock_canvas, (*tile_iter)->content_rect(), 1.0f, NULL); | 
| 261 | 262 | 
| 262 // This test verifies that when drawing the contents of a specific tile | 263 // This test verifies that when drawing the contents of a specific tile | 
| 263 // at content scale 1.0, the playback canvas never receives content from | 264 // at content scale 1.0, the playback canvas never receives content from | 
| 264 // neighboring tiles which indicates that the tile grid embedded in | 265 // neighboring tiles which indicates that the tile grid embedded in | 
| 265 // SkPicture is perfectly aligned with the compositor's tiles. | 266 // SkPicture is perfectly aligned with the compositor's tiles. | 
| 266 EXPECT_EQ(1u, mock_canvas.rects_.size()); | 267 EXPECT_EQ(1u, mock_canvas.rects_.size()); | 
| 267 EXPECT_RECT_EQ(*rect_iter, mock_canvas.rects_[0]); | 268 EXPECT_EQ(*rect_iter, mock_canvas.rects_[0]); | 
| 268 rect_iter++; | 269 rect_iter++; | 
| 269 } | 270 } | 
| 270 } | 271 } | 
| 271 | 272 | 
| 272 void TestQuadsForSolidColor(bool test_for_solid); | 273 void TestQuadsForSolidColor(bool test_for_solid); | 
| 273 | 274 | 
| 274 FakeImplProxy proxy_; | 275 FakeImplProxy proxy_; | 
| 275 TestSharedBitmapManager shared_bitmap_manager_; | 276 TestSharedBitmapManager shared_bitmap_manager_; | 
| 276 FakeLayerTreeHostImpl host_impl_; | 277 FakeLayerTreeHostImpl host_impl_; | 
| 277 int id_; | 278 int id_; | 
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 347 gfx::Transform transform, transform_for_tile_priority; | 348 gfx::Transform transform, transform_for_tile_priority; | 
| 348 | 349 | 
| 349 host_impl_.SetExternalDrawConstraints(transform, | 350 host_impl_.SetExternalDrawConstraints(transform, | 
| 350 viewport, | 351 viewport, | 
| 351 viewport, | 352 viewport, | 
| 352 viewport_rect_for_tile_priority, | 353 viewport_rect_for_tile_priority, | 
| 353 transform_for_tile_priority, | 354 transform_for_tile_priority, | 
| 354 resourceless_software_draw); | 355 resourceless_software_draw); | 
| 355 active_layer_->draw_properties().visible_content_rect = viewport; | 356 active_layer_->draw_properties().visible_content_rect = viewport; | 
| 356 active_layer_->draw_properties().screen_space_transform = transform; | 357 active_layer_->draw_properties().screen_space_transform = transform; | 
| 357 active_layer_->UpdateTiles(Occlusion()); | 358 active_layer_->UpdateTiles(Occlusion(), resourceless_software_draw); | 
| 358 | 359 | 
| 359 gfx::Rect viewport_rect_for_tile_priority_in_view_space = | 360 gfx::Rect viewport_rect_for_tile_priority_in_view_space = | 
| 360 viewport_rect_for_tile_priority; | 361 viewport_rect_for_tile_priority; | 
| 361 | 362 | 
| 362 // Verify the viewport rect for tile priority is used in picture layer impl. | 363 // Verify the viewport rect for tile priority is used in picture layer impl. | 
| 363 EXPECT_EQ(active_layer_->viewport_rect_for_tile_priority(), | 364 EXPECT_EQ(active_layer_->viewport_rect_for_tile_priority(), | 
| 364 viewport_rect_for_tile_priority_in_view_space); | 365 viewport_rect_for_tile_priority_in_view_space); | 
| 365 | 366 | 
| 366 // Verify the viewport rect for tile priority is used in picture layer tiling. | 367 // Verify the viewport rect for tile priority is used in picture layer tiling. | 
| 367 PictureLayerTilingSet* tilings = active_layer_->tilings(); | 368 PictureLayerTilingSet* tilings = active_layer_->tilings(); | 
| (...skipping 17 matching lines...) Expand all Loading... | |
| 385 transform_for_tile_priority.Translate(100, 100); | 386 transform_for_tile_priority.Translate(100, 100); | 
| 386 transform_for_tile_priority.Rotate(45); | 387 transform_for_tile_priority.Rotate(45); | 
| 387 host_impl_.SetExternalDrawConstraints(transform, | 388 host_impl_.SetExternalDrawConstraints(transform, | 
| 388 viewport, | 389 viewport, | 
| 389 viewport, | 390 viewport, | 
| 390 viewport_rect_for_tile_priority, | 391 viewport_rect_for_tile_priority, | 
| 391 transform_for_tile_priority, | 392 transform_for_tile_priority, | 
| 392 resourceless_software_draw); | 393 resourceless_software_draw); | 
| 393 active_layer_->draw_properties().visible_content_rect = viewport; | 394 active_layer_->draw_properties().visible_content_rect = viewport; | 
| 394 active_layer_->draw_properties().screen_space_transform = transform; | 395 active_layer_->draw_properties().screen_space_transform = transform; | 
| 395 active_layer_->UpdateTiles(Occlusion()); | 396 active_layer_->UpdateTiles(Occlusion(), resourceless_software_draw); | 
| 396 | 397 | 
| 397 gfx::Transform screen_to_view(gfx::Transform::kSkipInitialization); | 398 gfx::Transform screen_to_view(gfx::Transform::kSkipInitialization); | 
| 398 bool success = transform_for_tile_priority.GetInverse(&screen_to_view); | 399 bool success = transform_for_tile_priority.GetInverse(&screen_to_view); | 
| 399 EXPECT_TRUE(success); | 400 EXPECT_TRUE(success); | 
| 400 | 401 | 
| 401 // Note that we don't clip this to the layer bounds, since it is expected that | 402 // Note that we don't clip this to the layer bounds, since it is expected that | 
| 402 // the rect will sometimes be outside of the layer bounds. If we clip to | 403 // the rect will sometimes be outside of the layer bounds. If we clip to | 
| 403 // bounds, then tile priorities will end up being incorrect in cases of fully | 404 // bounds, then tile priorities will end up being incorrect in cases of fully | 
| 404 // offscreen layer. | 405 // offscreen layer. | 
| 405 viewport_rect_for_tile_priority_in_view_space = | 406 viewport_rect_for_tile_priority_in_view_space = | 
| 406 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( | 407 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( | 
| 407 screen_to_view, viewport_rect_for_tile_priority)); | 408 screen_to_view, viewport_rect_for_tile_priority)); | 
| 408 | 409 | 
| 409 // Verify the viewport rect for tile priority is used in PictureLayerImpl. | 410 // Verify the viewport rect for tile priority is used in PictureLayerImpl. | 
| 410 EXPECT_EQ(active_layer_->viewport_rect_for_tile_priority(), | 411 EXPECT_EQ(active_layer_->viewport_rect_for_tile_priority(), | 
| 411 viewport_rect_for_tile_priority_in_view_space); | 412 viewport_rect_for_tile_priority_in_view_space); | 
| 412 | 413 | 
| 413 tilings = active_layer_->tilings(); | 414 tilings = active_layer_->tilings(); | 
| 414 for (size_t i = 0; i < tilings->num_tilings(); i++) { | 415 for (size_t i = 0; i < tilings->num_tilings(); i++) { | 
| 415 PictureLayerTiling* tiling = tilings->tiling_at(i); | 416 PictureLayerTiling* tiling = tilings->tiling_at(i); | 
| 416 EXPECT_EQ( | 417 EXPECT_EQ( | 
| 417 tiling->GetCurrentVisibleRectForTesting(), | 418 tiling->GetCurrentVisibleRectForTesting(), | 
| 418 gfx::ScaleToEnclosingRect(viewport_rect_for_tile_priority_in_view_space, | 419 gfx::ScaleToEnclosingRect(viewport_rect_for_tile_priority_in_view_space, | 
| 419 tiling->contents_scale())); | 420 tiling->contents_scale())); | 
| 420 } | 421 } | 
| 421 } | 422 } | 
| 422 | 423 | 
| 423 TEST_F(PictureLayerImplTest, | 424 TEST_F(PictureLayerImplTest, InvalidViewportForPrioritizingTiles) { | 
| 424 ResourcelessSoftwareDrawHasValidViewportForTilePriority) { | |
| 425 base::TimeTicks time_ticks; | 425 base::TimeTicks time_ticks; | 
| 426 time_ticks += base::TimeDelta::FromMilliseconds(1); | 426 time_ticks += base::TimeDelta::FromMilliseconds(1); | 
| 427 host_impl_.SetCurrentBeginFrameArgs( | 427 host_impl_.SetCurrentBeginFrameArgs( | 
| 428 CreateBeginFrameArgsForTesting(time_ticks)); | 428 CreateBeginFrameArgsForTesting(time_ticks)); | 
| 429 | 429 | 
| 430 gfx::Size tile_size(100, 100); | 430 gfx::Size tile_size(100, 100); | 
| 431 gfx::Size layer_bounds(400, 400); | 431 gfx::Size layer_bounds(400, 400); | 
| 432 | 432 | 
| 433 scoped_refptr<FakePicturePileImpl> pending_pile = | 433 scoped_refptr<FakePicturePileImpl> pending_pile = | 
| 434 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 434 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 
| 435 scoped_refptr<FakePicturePileImpl> active_pile = | 435 scoped_refptr<FakePicturePileImpl> active_pile = | 
| 436 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 436 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 
| 437 | 437 | 
| 438 SetupTrees(pending_pile, active_pile); | 438 SetupTrees(pending_pile, active_pile); | 
| 439 | 439 | 
| 440 Region invalidation; | 440 Region invalidation; | 
| 441 AddDefaultTilingsWithInvalidation(invalidation); | 441 AddDefaultTilingsWithInvalidation(invalidation); | 
| 442 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, false); | 442 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, false); | 
| 443 | 443 | 
| 444 // UpdateTiles with valid viewport. Should update tile viewport. | 444 // UpdateTiles with valid viewport. Should update tile viewport. | 
| 445 // Note viewport is considered invalid if and only if in resourceless | |
| 446 // software draw. | |
| 445 bool resourceless_software_draw = false; | 447 bool resourceless_software_draw = false; | 
| 446 gfx::Rect viewport = gfx::Rect(layer_bounds); | 448 gfx::Rect viewport = gfx::Rect(layer_bounds); | 
| 447 gfx::Transform transform; | 449 gfx::Transform transform; | 
| 448 host_impl_.SetExternalDrawConstraints(transform, | 450 host_impl_.SetExternalDrawConstraints(transform, | 
| 449 viewport, | 451 viewport, | 
| 450 viewport, | 452 viewport, | 
| 451 viewport, | 453 viewport, | 
| 452 transform, | 454 transform, | 
| 453 resourceless_software_draw); | 455 resourceless_software_draw); | 
| 454 active_layer_->draw_properties().visible_content_rect = viewport; | 456 active_layer_->draw_properties().visible_content_rect = viewport; | 
| 455 active_layer_->draw_properties().screen_space_transform = transform; | 457 active_layer_->draw_properties().screen_space_transform = transform; | 
| 456 active_layer_->UpdateTiles(Occlusion()); | 458 active_layer_->UpdateTiles(Occlusion(), resourceless_software_draw); | 
| 457 | 459 | 
| 458 gfx::Rect visible_rect_for_tile_priority = | 460 gfx::Rect visible_rect_for_tile_priority = | 
| 459 active_layer_->visible_rect_for_tile_priority(); | 461 active_layer_->visible_rect_for_tile_priority(); | 
| 460 EXPECT_FALSE(visible_rect_for_tile_priority.IsEmpty()); | 462 EXPECT_FALSE(visible_rect_for_tile_priority.IsEmpty()); | 
| 461 gfx::Rect viewport_rect_for_tile_priority = | 463 gfx::Rect viewport_rect_for_tile_priority = | 
| 462 active_layer_->viewport_rect_for_tile_priority(); | 464 active_layer_->viewport_rect_for_tile_priority(); | 
| 463 EXPECT_FALSE(viewport_rect_for_tile_priority.IsEmpty()); | 465 EXPECT_FALSE(viewport_rect_for_tile_priority.IsEmpty()); | 
| 464 gfx::Transform screen_space_transform_for_tile_priority = | 466 gfx::Transform screen_space_transform_for_tile_priority = | 
| 465 active_layer_->screen_space_transform_for_tile_priority(); | 467 active_layer_->screen_space_transform_for_tile_priority(); | 
| 466 | 468 | 
| 467 // PictureLayerImpl does not make a special case for | 469 // Expand viewport and set it as invalid for prioritizing tiles. | 
| 468 // resource_less_software_draw, so the tile viewport and matrix should be | 470 // Should update viewport and transform, but not update visible rect. | 
| 469 // respected. | |
| 470 time_ticks += base::TimeDelta::FromMilliseconds(200); | 471 time_ticks += base::TimeDelta::FromMilliseconds(200); | 
| 471 host_impl_.SetCurrentBeginFrameArgs( | 472 host_impl_.SetCurrentBeginFrameArgs( | 
| 472 CreateBeginFrameArgsForTesting(time_ticks)); | 473 CreateBeginFrameArgsForTesting(time_ticks)); | 
| 473 resourceless_software_draw = true; | 474 resourceless_software_draw = true; | 
| 474 viewport = gfx::ScaleToEnclosingRect(viewport, 2); | 475 viewport = gfx::ScaleToEnclosingRect(viewport, 2); | 
| 475 transform.Translate(1.f, 1.f); | 476 transform.Translate(1.f, 1.f); | 
| 476 active_layer_->draw_properties().visible_content_rect = viewport; | 477 active_layer_->draw_properties().visible_content_rect = viewport; | 
| 477 active_layer_->draw_properties().screen_space_transform = transform; | 478 active_layer_->draw_properties().screen_space_transform = transform; | 
| 478 host_impl_.SetExternalDrawConstraints(transform, | 479 host_impl_.SetExternalDrawConstraints(transform, | 
| 479 viewport, | 480 viewport, | 
| 480 viewport, | 481 viewport, | 
| 481 viewport, | 482 viewport, | 
| 482 transform, | 483 transform, | 
| 483 resourceless_software_draw); | 484 resourceless_software_draw); | 
| 484 active_layer_->UpdateTiles(Occlusion()); | 485 active_layer_->UpdateTiles(Occlusion(), resourceless_software_draw); | 
| 485 | 486 | 
| 486 visible_rect_for_tile_priority = | 487 // Viewport and transform for tile priority are updated. | 
| 487 gfx::ScaleToEnclosingRect(visible_rect_for_tile_priority, 2); | 488 EXPECT_EQ(viewport, active_layer_->viewport_rect_for_tile_priority()); | 
| 488 viewport_rect_for_tile_priority = | |
| 489 gfx::ScaleToEnclosingRect(viewport_rect_for_tile_priority, 2); | |
| 490 screen_space_transform_for_tile_priority = transform; | |
| 491 EXPECT_RECT_EQ(visible_rect_for_tile_priority, | |
| 492 active_layer_->visible_rect_for_tile_priority()); | |
| 493 EXPECT_RECT_EQ(viewport_rect_for_tile_priority, | |
| 494 active_layer_->viewport_rect_for_tile_priority()); | |
| 495 EXPECT_TRANSFORMATION_MATRIX_EQ( | 489 EXPECT_TRANSFORMATION_MATRIX_EQ( | 
| 496 screen_space_transform_for_tile_priority, | 490 transform, active_layer_->screen_space_transform_for_tile_priority()); | 
| 497 active_layer_->screen_space_transform_for_tile_priority()); | 491 // Visible rect for tile priority retains old value. | 
| 492 EXPECT_EQ(visible_rect_for_tile_priority, | |
| 493 active_layer_->visible_rect_for_tile_priority()); | |
| 494 | |
| 495 // Keep expanded viewport but mark it valid. Should update tile viewport. | |
| 496 time_ticks += base::TimeDelta::FromMilliseconds(200); | |
| 497 host_impl_.SetCurrentBeginFrameArgs( | |
| 498 CreateBeginFrameArgsForTesting(time_ticks)); | |
| 499 resourceless_software_draw = false; | |
| 500 host_impl_.SetExternalDrawConstraints(transform, | |
| 501 viewport, | |
| 502 viewport, | |
| 503 viewport, | |
| 504 transform, | |
| 505 resourceless_software_draw); | |
| 506 active_layer_->UpdateTiles(Occlusion(), resourceless_software_draw); | |
| 507 | |
| 508 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 509 transform, active_layer_->screen_space_transform_for_tile_priority()); | |
| 510 EXPECT_EQ(viewport, active_layer_->visible_rect_for_tile_priority()); | |
| 511 | |
| 512 // Match the reverse translate in |transform|. | |
| 513 EXPECT_EQ(viewport - gfx::Vector2d(1, 1), | |
| 514 active_layer_->viewport_rect_for_tile_priority()); | |
| 498 } | 515 } | 
| 499 | 516 | 
| 500 TEST_F(PictureLayerImplTest, ClonePartialInvalidation) { | 517 TEST_F(PictureLayerImplTest, ClonePartialInvalidation) { | 
| 501 gfx::Size tile_size(100, 100); | 518 gfx::Size tile_size(100, 100); | 
| 502 gfx::Size layer_bounds(400, 400); | 519 gfx::Size layer_bounds(400, 400); | 
| 503 gfx::Rect layer_invalidation(150, 200, 30, 180); | 520 gfx::Rect layer_invalidation(150, 200, 30, 180); | 
| 504 | 521 | 
| 505 scoped_refptr<FakePicturePileImpl> pending_pile = | 522 scoped_refptr<FakePicturePileImpl> pending_pile = | 
| 506 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 523 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 
| 507 scoped_refptr<FakePicturePileImpl> active_pile = | 524 scoped_refptr<FakePicturePileImpl> active_pile = | 
| (...skipping 904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1412 } | 1429 } | 
| 1413 | 1430 | 
| 1414 TEST_F(PictureLayerImplTest, MarkRequiredOffscreenTiles) { | 1431 TEST_F(PictureLayerImplTest, MarkRequiredOffscreenTiles) { | 
| 1415 gfx::Size tile_size(100, 100); | 1432 gfx::Size tile_size(100, 100); | 
| 1416 gfx::Size layer_bounds(200, 200); | 1433 gfx::Size layer_bounds(200, 200); | 
| 1417 | 1434 | 
| 1418 scoped_refptr<FakePicturePileImpl> pending_pile = | 1435 scoped_refptr<FakePicturePileImpl> pending_pile = | 
| 1419 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 1436 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 
| 1420 SetupPendingTree(pending_pile); | 1437 SetupPendingTree(pending_pile); | 
| 1421 | 1438 | 
| 1439 gfx::Transform transform; | |
| 1440 gfx::Transform transform_for_tile_priority; | |
| 1441 bool resourceless_software_draw = false; | |
| 1442 gfx::Rect viewport(0, 0, 100, 200); | |
| 1443 host_impl_.SetExternalDrawConstraints(transform, | |
| 1444 viewport, | |
| 1445 viewport, | |
| 1446 viewport, | |
| 1447 transform, | |
| 1448 resourceless_software_draw); | |
| 1449 | |
| 1422 pending_layer_->set_fixed_tile_size(tile_size); | 1450 pending_layer_->set_fixed_tile_size(tile_size); | 
| 1423 ASSERT_TRUE(pending_layer_->CanHaveTilings()); | 1451 ASSERT_TRUE(pending_layer_->CanHaveTilings()); | 
| 1424 PictureLayerTiling* tiling = pending_layer_->AddTiling(1.f); | 1452 PictureLayerTiling* tiling = pending_layer_->AddTiling(1.f); | 
| 1425 host_impl_.pending_tree()->UpdateDrawProperties(); | 1453 host_impl_.pending_tree()->UpdateDrawProperties(); | 
| 1426 EXPECT_EQ(tiling->resolution(), HIGH_RESOLUTION); | 1454 EXPECT_EQ(tiling->resolution(), HIGH_RESOLUTION); | 
| 1427 | 1455 EXPECT_EQ(viewport, pending_layer_->visible_rect_for_tile_priority()); | 
| 1428 pending_layer_->draw_properties().visible_content_rect = | |
| 1429 gfx::Rect(0, 0, 100, 200); | |
| 1430 | 1456 | 
| 1431 // Fake set priorities. | 1457 // Fake set priorities. | 
| 1432 for (PictureLayerTiling::CoverageIterator iter( | 1458 for (PictureLayerTiling::CoverageIterator iter( | 
| 1433 tiling, pending_layer_->contents_scale_x(), gfx::Rect(layer_bounds)); | 1459 tiling, pending_layer_->contents_scale_x(), gfx::Rect(layer_bounds)); | 
| 1434 iter; | 1460 iter; | 
| 1435 ++iter) { | 1461 ++iter) { | 
| 1436 if (!*iter) | 1462 if (!*iter) | 
| 1437 continue; | 1463 continue; | 
| 1438 Tile* tile = *iter; | 1464 Tile* tile = *iter; | 
| 1439 TilePriority priority; | 1465 TilePriority priority; | 
| 1440 priority.resolution = HIGH_RESOLUTION; | 1466 priority.resolution = HIGH_RESOLUTION; | 
| 1441 gfx::Rect tile_bounds = iter.geometry_rect(); | 1467 gfx::Rect tile_bounds = iter.geometry_rect(); | 
| 1442 if (pending_layer_->visible_content_rect().Intersects(tile_bounds)) { | 1468 if (pending_layer_->visible_rect_for_tile_priority().Intersects( | 
| 1469 tile_bounds)) { | |
| 1443 priority.priority_bin = TilePriority::NOW; | 1470 priority.priority_bin = TilePriority::NOW; | 
| 1444 priority.distance_to_visible = 0.f; | 1471 priority.distance_to_visible = 0.f; | 
| 1445 } else { | 1472 } else { | 
| 1446 priority.priority_bin = TilePriority::SOON; | 1473 priority.priority_bin = TilePriority::SOON; | 
| 1447 priority.distance_to_visible = 1.f; | 1474 priority.distance_to_visible = 1.f; | 
| 1448 } | 1475 } | 
| 1449 tile->SetPriority(PENDING_TREE, priority); | 1476 tile->SetPriority(PENDING_TREE, priority); | 
| 1450 } | 1477 } | 
| 1451 | 1478 | 
| 1452 pending_layer_->MarkVisibleResourcesAsRequired(); | 1479 pending_layer_->MarkVisibleResourcesAsRequired(); | 
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1508 transform_for_tile_priority, | 1535 transform_for_tile_priority, | 
| 1509 resourceless_software_draw); | 1536 resourceless_software_draw); | 
| 1510 host_impl_.pending_tree()->UpdateDrawProperties(); | 1537 host_impl_.pending_tree()->UpdateDrawProperties(); | 
| 1511 | 1538 | 
| 1512 // Set visible content rect that is different from | 1539 // Set visible content rect that is different from | 
| 1513 // external_viewport_for_tile_priority. | 1540 // external_viewport_for_tile_priority. | 
| 1514 pending_layer_->draw_properties().visible_content_rect = visible_content_rect; | 1541 pending_layer_->draw_properties().visible_content_rect = visible_content_rect; | 
| 1515 time_ticks += base::TimeDelta::FromMilliseconds(200); | 1542 time_ticks += base::TimeDelta::FromMilliseconds(200); | 
| 1516 host_impl_.SetCurrentBeginFrameArgs( | 1543 host_impl_.SetCurrentBeginFrameArgs( | 
| 1517 CreateBeginFrameArgsForTesting(time_ticks)); | 1544 CreateBeginFrameArgsForTesting(time_ticks)); | 
| 1518 pending_layer_->UpdateTiles(Occlusion()); | 1545 pending_layer_->UpdateTiles(Occlusion(), resourceless_software_draw); | 
| 1519 | 1546 | 
| 1520 pending_layer_->MarkVisibleResourcesAsRequired(); | 1547 pending_layer_->MarkVisibleResourcesAsRequired(); | 
| 1521 | 1548 | 
| 1522 // Intersect the two rects. Any tile outside should not be required for | 1549 // Intersect the two rects. Any tile outside should not be required for | 
| 1523 // activation. | 1550 // activation. | 
| 1524 gfx::Rect viewport_for_tile_priority = | 1551 gfx::Rect viewport_for_tile_priority = | 
| 1525 pending_layer_->GetViewportForTilePriorityInContentSpace(); | 1552 pending_layer_->GetViewportForTilePriorityInContentSpace(); | 
| 1526 viewport_for_tile_priority.Intersect(pending_layer_->visible_content_rect()); | 1553 viewport_for_tile_priority.Intersect(pending_layer_->visible_content_rect()); | 
| 1527 | 1554 | 
| 1528 int num_inside = 0; | 1555 int num_inside = 0; | 
| (...skipping 1043 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2572 EXPECT_EQ(low_res_tile_count + high_res_tile_count + non_ideal_tile_count, | 2599 EXPECT_EQ(low_res_tile_count + high_res_tile_count + non_ideal_tile_count, | 
| 2573 unique_tiles.size()); | 2600 unique_tiles.size()); | 
| 2574 | 2601 | 
| 2575 // No NOW tiles. | 2602 // No NOW tiles. | 
| 2576 time_ticks += base::TimeDelta::FromMilliseconds(200); | 2603 time_ticks += base::TimeDelta::FromMilliseconds(200); | 
| 2577 host_impl_.SetCurrentBeginFrameArgs( | 2604 host_impl_.SetCurrentBeginFrameArgs( | 
| 2578 CreateBeginFrameArgsForTesting(time_ticks)); | 2605 CreateBeginFrameArgsForTesting(time_ticks)); | 
| 2579 | 2606 | 
| 2580 pending_layer_->draw_properties().visible_content_rect = | 2607 pending_layer_->draw_properties().visible_content_rect = | 
| 2581 gfx::Rect(1100, 1100, 500, 500); | 2608 gfx::Rect(1100, 1100, 500, 500); | 
| 2582 pending_layer_->UpdateTiles(Occlusion()); | 2609 bool resourceless_software_draw = false; | 
| 2610 pending_layer_->UpdateTiles(Occlusion(), resourceless_software_draw); | |
| 2583 | 2611 | 
| 2584 unique_tiles.clear(); | 2612 unique_tiles.clear(); | 
| 2585 high_res_tile_count = 0u; | 2613 high_res_tile_count = 0u; | 
| 2586 for (it = PictureLayerImpl::LayerRasterTileIterator(pending_layer_, false); | 2614 for (it = PictureLayerImpl::LayerRasterTileIterator(pending_layer_, false); | 
| 2587 it; | 2615 it; | 
| 2588 ++it) { | 2616 ++it) { | 
| 2589 Tile* tile = *it; | 2617 Tile* tile = *it; | 
| 2590 TilePriority priority = tile->priority(PENDING_TREE); | 2618 TilePriority priority = tile->priority(PENDING_TREE); | 
| 2591 | 2619 | 
| 2592 EXPECT_TRUE(tile); | 2620 EXPECT_TRUE(tile); | 
| 2593 | 2621 | 
| 2594 // Non-high res tiles only get visible tiles. | 2622 // Non-high res tiles only get visible tiles. | 
| 2595 EXPECT_EQ(HIGH_RESOLUTION, priority.resolution); | 2623 EXPECT_EQ(HIGH_RESOLUTION, priority.resolution); | 
| 2596 EXPECT_NE(TilePriority::NOW, priority.priority_bin); | 2624 EXPECT_NE(TilePriority::NOW, priority.priority_bin); | 
| 2597 | 2625 | 
| 2598 high_res_tile_count += priority.resolution == HIGH_RESOLUTION; | 2626 high_res_tile_count += priority.resolution == HIGH_RESOLUTION; | 
| 2599 | 2627 | 
| 2600 unique_tiles.insert(tile); | 2628 unique_tiles.insert(tile); | 
| 2601 } | 2629 } | 
| 2602 | 2630 | 
| 2603 EXPECT_EQ(16u, high_res_tile_count); | 2631 EXPECT_EQ(16u, high_res_tile_count); | 
| 2604 EXPECT_EQ(high_res_tile_count, unique_tiles.size()); | 2632 EXPECT_EQ(high_res_tile_count, unique_tiles.size()); | 
| 2605 | 2633 | 
| 2606 time_ticks += base::TimeDelta::FromMilliseconds(200); | 2634 time_ticks += base::TimeDelta::FromMilliseconds(200); | 
| 2607 host_impl_.SetCurrentBeginFrameArgs( | 2635 host_impl_.SetCurrentBeginFrameArgs( | 
| 2608 CreateBeginFrameArgsForTesting(time_ticks)); | 2636 CreateBeginFrameArgsForTesting(time_ticks)); | 
| 2609 | 2637 | 
| 2610 pending_layer_->draw_properties().visible_content_rect = | 2638 pending_layer_->draw_properties().visible_content_rect = | 
| 2611 gfx::Rect(0, 0, 500, 500); | 2639 gfx::Rect(0, 0, 500, 500); | 
| 2612 pending_layer_->UpdateTiles(Occlusion()); | 2640 pending_layer_->UpdateTiles(Occlusion(), resourceless_software_draw); | 
| 2613 | 2641 | 
| 2614 std::vector<Tile*> high_res_tiles = high_res_tiling->AllTilesForTesting(); | 2642 std::vector<Tile*> high_res_tiles = high_res_tiling->AllTilesForTesting(); | 
| 2615 for (std::vector<Tile*>::iterator tile_it = high_res_tiles.begin(); | 2643 for (std::vector<Tile*>::iterator tile_it = high_res_tiles.begin(); | 
| 2616 tile_it != high_res_tiles.end(); | 2644 tile_it != high_res_tiles.end(); | 
| 2617 ++tile_it) { | 2645 ++tile_it) { | 
| 2618 Tile* tile = *tile_it; | 2646 Tile* tile = *tile_it; | 
| 2619 ManagedTileState::DrawInfo& draw_info = tile->draw_info(); | 2647 ManagedTileState::DrawInfo& draw_info = tile->draw_info(); | 
| 2620 draw_info.SetSolidColorForTesting(SK_ColorRED); | 2648 draw_info.SetSolidColorForTesting(SK_ColorRED); | 
| 2621 } | 2649 } | 
| 2622 | 2650 | 
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3123 EXPECT_EQ(active_layer_->HighResTiling()->AllTilesForTesting().size(), 0u); | 3151 EXPECT_EQ(active_layer_->HighResTiling()->AllTilesForTesting().size(), 0u); | 
| 3124 | 3152 | 
| 3125 // Since the active layer has no tiles at all, the pending layer doesn't | 3153 // Since the active layer has no tiles at all, the pending layer doesn't | 
| 3126 // need content in order to activate. | 3154 // need content in order to activate. | 
| 3127 pending_layer_->MarkVisibleResourcesAsRequired(); | 3155 pending_layer_->MarkVisibleResourcesAsRequired(); | 
| 3128 AssertNoTilesRequired(pending_layer_->HighResTiling()); | 3156 AssertNoTilesRequired(pending_layer_->HighResTiling()); | 
| 3129 if (host_impl_.settings().create_low_res_tiling) | 3157 if (host_impl_.settings().create_low_res_tiling) | 
| 3130 AssertNoTilesRequired(pending_layer_->LowResTiling()); | 3158 AssertNoTilesRequired(pending_layer_->LowResTiling()); | 
| 3131 } | 3159 } | 
| 3132 | 3160 | 
| 3133 TEST_F(NoLowResPictureLayerImplTest, | 3161 TEST_F(NoLowResPictureLayerImplTest, InvalidViewportForPrioritizingTiles) { | 
| 3134 ResourcelessSoftwareDrawHasValidViewportForTilePriority) { | |
| 3135 base::TimeTicks time_ticks; | 3162 base::TimeTicks time_ticks; | 
| 3136 time_ticks += base::TimeDelta::FromMilliseconds(1); | 3163 time_ticks += base::TimeDelta::FromMilliseconds(1); | 
| 3137 host_impl_.SetCurrentBeginFrameArgs( | 3164 host_impl_.SetCurrentBeginFrameArgs( | 
| 3138 CreateBeginFrameArgsForTesting(time_ticks)); | 3165 CreateBeginFrameArgsForTesting(time_ticks)); | 
| 3139 | 3166 | 
| 3140 gfx::Size tile_size(100, 100); | 3167 gfx::Size tile_size(100, 100); | 
| 3141 gfx::Size layer_bounds(400, 400); | 3168 gfx::Size layer_bounds(400, 400); | 
| 3142 | 3169 | 
| 3143 scoped_refptr<FakePicturePileImpl> pending_pile = | 3170 scoped_refptr<FakePicturePileImpl> pending_pile = | 
| 3144 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 3171 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 
| 3145 scoped_refptr<FakePicturePileImpl> active_pile = | 3172 scoped_refptr<FakePicturePileImpl> active_pile = | 
| 3146 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 3173 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 
| 3147 | 3174 | 
| 3148 SetupTrees(pending_pile, active_pile); | 3175 SetupTrees(pending_pile, active_pile); | 
| 3149 | 3176 | 
| 3150 Region invalidation; | 3177 Region invalidation; | 
| 3151 AddDefaultTilingsWithInvalidation(invalidation); | 3178 AddDefaultTilingsWithInvalidation(invalidation); | 
| 3152 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, false); | 3179 SetupDrawPropertiesAndUpdateTiles(active_layer_, 1.f, 1.f, 1.f, 1.f, false); | 
| 3153 | 3180 | 
| 3154 // UpdateTiles with valid viewport. Should update tile viewport. | 3181 // UpdateTiles with valid viewport. Should update tile viewport. | 
| 3182 // Note viewport is considered invalid if and only if in resourceless | |
| 3183 // software draw. | |
| 3155 bool resourceless_software_draw = false; | 3184 bool resourceless_software_draw = false; | 
| 3156 gfx::Rect viewport = gfx::Rect(layer_bounds); | 3185 gfx::Rect viewport = gfx::Rect(layer_bounds); | 
| 3157 gfx::Transform transform; | 3186 gfx::Transform transform; | 
| 3158 host_impl_.SetExternalDrawConstraints(transform, | 3187 host_impl_.SetExternalDrawConstraints(transform, | 
| 3159 viewport, | 3188 viewport, | 
| 3160 viewport, | 3189 viewport, | 
| 3161 viewport, | 3190 viewport, | 
| 3162 transform, | 3191 transform, | 
| 3163 resourceless_software_draw); | 3192 resourceless_software_draw); | 
| 3164 active_layer_->draw_properties().visible_content_rect = viewport; | 3193 active_layer_->draw_properties().visible_content_rect = viewport; | 
| 3165 active_layer_->draw_properties().screen_space_transform = transform; | 3194 active_layer_->draw_properties().screen_space_transform = transform; | 
| 3166 active_layer_->UpdateTiles(Occlusion()); | 3195 active_layer_->UpdateTiles(Occlusion(), resourceless_software_draw); | 
| 3167 | 3196 | 
| 3168 gfx::Rect visible_rect_for_tile_priority = | 3197 gfx::Rect visible_rect_for_tile_priority = | 
| 3169 active_layer_->visible_rect_for_tile_priority(); | 3198 active_layer_->visible_rect_for_tile_priority(); | 
| 3170 EXPECT_FALSE(visible_rect_for_tile_priority.IsEmpty()); | 3199 EXPECT_FALSE(visible_rect_for_tile_priority.IsEmpty()); | 
| 3171 gfx::Rect viewport_rect_for_tile_priority = | 3200 gfx::Rect viewport_rect_for_tile_priority = | 
| 3172 active_layer_->viewport_rect_for_tile_priority(); | 3201 active_layer_->viewport_rect_for_tile_priority(); | 
| 3173 EXPECT_FALSE(viewport_rect_for_tile_priority.IsEmpty()); | 3202 EXPECT_FALSE(viewport_rect_for_tile_priority.IsEmpty()); | 
| 3174 gfx::Transform screen_space_transform_for_tile_priority = | 3203 gfx::Transform screen_space_transform_for_tile_priority = | 
| 3175 active_layer_->screen_space_transform_for_tile_priority(); | 3204 active_layer_->screen_space_transform_for_tile_priority(); | 
| 3176 | 3205 | 
| 3177 // PictureLayerImpl does not make a special case for | 3206 // Expand viewport and set it as invalid for prioritizing tiles. | 
| 3178 // resource_less_software_draw, so the tile viewport and matrix should be | 3207 // Should update viewport and transform, but not update visible rect. | 
| 3179 // respected. | |
| 3180 time_ticks += base::TimeDelta::FromMilliseconds(200); | 3208 time_ticks += base::TimeDelta::FromMilliseconds(200); | 
| 3181 host_impl_.SetCurrentBeginFrameArgs( | 3209 host_impl_.SetCurrentBeginFrameArgs( | 
| 3182 CreateBeginFrameArgsForTesting(time_ticks)); | 3210 CreateBeginFrameArgsForTesting(time_ticks)); | 
| 3183 resourceless_software_draw = true; | 3211 resourceless_software_draw = true; | 
| 3184 viewport = gfx::ScaleToEnclosingRect(viewport, 2); | 3212 viewport = gfx::ScaleToEnclosingRect(viewport, 2); | 
| 3185 transform.Translate(1.f, 1.f); | 3213 transform.Translate(1.f, 1.f); | 
| 3186 active_layer_->draw_properties().visible_content_rect = viewport; | 3214 active_layer_->draw_properties().visible_content_rect = viewport; | 
| 3187 active_layer_->draw_properties().screen_space_transform = transform; | 3215 active_layer_->draw_properties().screen_space_transform = transform; | 
| 3188 host_impl_.SetExternalDrawConstraints(transform, | 3216 host_impl_.SetExternalDrawConstraints(transform, | 
| 3189 viewport, | 3217 viewport, | 
| 3190 viewport, | 3218 viewport, | 
| 3191 viewport, | 3219 viewport, | 
| 3192 transform, | 3220 transform, | 
| 3193 resourceless_software_draw); | 3221 resourceless_software_draw); | 
| 3194 active_layer_->UpdateTiles(Occlusion()); | 3222 active_layer_->UpdateTiles(Occlusion(), resourceless_software_draw); | 
| 3195 | 3223 | 
| 3196 visible_rect_for_tile_priority = | 3224 // Viewport and transform for tile priority are updated. | 
| 3197 gfx::ScaleToEnclosingRect(visible_rect_for_tile_priority, 2); | 3225 EXPECT_EQ(viewport, active_layer_->viewport_rect_for_tile_priority()); | 
| 3198 viewport_rect_for_tile_priority = | 3226 EXPECT_TRANSFORMATION_MATRIX_EQ( | 
| 3199 gfx::ScaleToEnclosingRect(viewport_rect_for_tile_priority, 2); | 3227 transform, active_layer_->screen_space_transform_for_tile_priority()); | 
| 3200 screen_space_transform_for_tile_priority = transform; | 3228 // Visible rect for tile priority retains old value. | 
| 3229 EXPECT_EQ(visible_rect_for_tile_priority, | |
| 3230 active_layer_->visible_rect_for_tile_priority()); | |
| 3201 | 3231 | 
| 3202 EXPECT_RECT_EQ(visible_rect_for_tile_priority, | 3232 // Keep expanded viewport but mark it valid. Should update tile viewport. | 
| 3203 active_layer_->visible_rect_for_tile_priority()); | 3233 time_ticks += base::TimeDelta::FromMilliseconds(200); | 
| 3204 EXPECT_RECT_EQ(viewport_rect_for_tile_priority, | 3234 host_impl_.SetCurrentBeginFrameArgs( | 
| 3205 active_layer_->viewport_rect_for_tile_priority()); | 3235 CreateBeginFrameArgsForTesting(time_ticks)); | 
| 3236 resourceless_software_draw = false; | |
| 3237 host_impl_.SetExternalDrawConstraints(transform, | |
| 3238 viewport, | |
| 3239 viewport, | |
| 3240 viewport, | |
| 3241 transform, | |
| 3242 resourceless_software_draw); | |
| 3243 active_layer_->UpdateTiles(Occlusion(), resourceless_software_draw); | |
| 3244 | |
| 3206 EXPECT_TRANSFORMATION_MATRIX_EQ( | 3245 EXPECT_TRANSFORMATION_MATRIX_EQ( | 
| 3207 screen_space_transform_for_tile_priority, | 3246 transform, active_layer_->screen_space_transform_for_tile_priority()); | 
| 3208 active_layer_->screen_space_transform_for_tile_priority()); | 3247 EXPECT_EQ(viewport, active_layer_->visible_rect_for_tile_priority()); | 
| 3248 | |
| 3249 gfx::Rect viewport_rect_in_layer = | |
| 3250 active_layer_->viewport_rect_for_tile_priority(); | |
| 3251 viewport_rect_in_layer.Offset(1, 1); // Match translate in |transform|. | |
| 
 
danakj
2014/10/01 14:27:14
can you make this look the same as what you did ab
 
boliu
2014/10/01 15:20:47
Oops. Done.
 
 | |
| 3252 EXPECT_EQ(viewport, viewport_rect_in_layer); | |
| 3209 } | 3253 } | 
| 3210 | 3254 | 
| 3211 TEST_F(NoLowResPictureLayerImplTest, CleanUpTilings) { | 3255 TEST_F(NoLowResPictureLayerImplTest, CleanUpTilings) { | 
| 3212 gfx::Size tile_size(400, 400); | 3256 gfx::Size tile_size(400, 400); | 
| 3213 gfx::Size layer_bounds(1300, 1900); | 3257 gfx::Size layer_bounds(1300, 1900); | 
| 3214 | 3258 | 
| 3215 scoped_refptr<FakePicturePileImpl> pending_pile = | 3259 scoped_refptr<FakePicturePileImpl> pending_pile = | 
| 3216 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 3260 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 
| 3217 scoped_refptr<FakePicturePileImpl> active_pile = | 3261 scoped_refptr<FakePicturePileImpl> active_pile = | 
| 3218 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 3262 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 
| (...skipping 1139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4358 SetupPendingTree(pending_pile2); | 4402 SetupPendingTree(pending_pile2); | 
| 4359 ActivateTree(); | 4403 ActivateTree(); | 
| 4360 | 4404 | 
| 4361 // We've switched to a solid color, so we should end up with no tilings. | 4405 // We've switched to a solid color, so we should end up with no tilings. | 
| 4362 ASSERT_TRUE(active_layer_->tilings()); | 4406 ASSERT_TRUE(active_layer_->tilings()); | 
| 4363 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); | 4407 EXPECT_EQ(0u, active_layer_->tilings()->num_tilings()); | 
| 4364 } | 4408 } | 
| 4365 | 4409 | 
| 4366 } // namespace | 4410 } // namespace | 
| 4367 } // namespace cc | 4411 } // namespace cc | 
| OLD | NEW |