| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/delegated_renderer_layer_impl.h" | 5 #include "cc/layers/delegated_renderer_layer_impl.h" |
| 6 | 6 |
| 7 #include "cc/base/scoped_ptr_vector.h" | 7 #include "cc/base/scoped_ptr_vector.h" |
| 8 #include "cc/layers/solid_color_layer_impl.h" | 8 #include "cc/layers/solid_color_layer_impl.h" |
| 9 #include "cc/quads/render_pass_draw_quad.h" | 9 #include "cc/quads/render_pass_draw_quad.h" |
| 10 #include "cc/quads/solid_color_draw_quad.h" | 10 #include "cc/quads/solid_color_draw_quad.h" |
| (...skipping 1356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1367 EXPECT_EQ(DrawQuad::SOLID_COLOR, | 1367 EXPECT_EQ(DrawQuad::SOLID_COLOR, |
| 1368 frame.render_passes[0]->quad_list[0]->material); | 1368 frame.render_passes[0]->quad_list[0]->material); |
| 1369 | 1369 |
| 1370 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); | 1370 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); |
| 1371 host_impl_->DidDrawAllLayers(frame); | 1371 host_impl_->DidDrawAllLayers(frame); |
| 1372 } | 1372 } |
| 1373 | 1373 |
| 1374 TEST_F(DelegatedRendererLayerImplTest, Occlusion) { | 1374 TEST_F(DelegatedRendererLayerImplTest, Occlusion) { |
| 1375 gfx::Size layer_size(1000, 1000); | 1375 gfx::Size layer_size(1000, 1000); |
| 1376 gfx::Size viewport_size(1000, 1000); | 1376 gfx::Size viewport_size(1000, 1000); |
| 1377 gfx::Rect quad_rect(200, 300, 400, 500); | 1377 gfx::Rect quad_screen_rect(211, 300, 400, 500); |
| 1378 | 1378 |
| 1379 gfx::Transform transform; | 1379 gfx::Transform transform; |
| 1380 transform.Translate(11.0, 0.0); | 1380 transform.Translate(211.0, 300.0); |
| 1381 | 1381 |
| 1382 LayerTestCommon::LayerImplTest impl; | 1382 LayerTestCommon::LayerImplTest impl; |
| 1383 | 1383 |
| 1384 FakeDelegatedRendererLayerImpl* delegated_renderer_layer_impl = | 1384 FakeDelegatedRendererLayerImpl* delegated_renderer_layer_impl = |
| 1385 impl.AddChildToRoot<FakeDelegatedRendererLayerImpl>(); | 1385 impl.AddChildToRoot<FakeDelegatedRendererLayerImpl>(); |
| 1386 delegated_renderer_layer_impl->SetBounds(layer_size); | 1386 delegated_renderer_layer_impl->SetBounds(layer_size); |
| 1387 delegated_renderer_layer_impl->SetContentBounds(layer_size); | 1387 delegated_renderer_layer_impl->SetContentBounds(layer_size); |
| 1388 delegated_renderer_layer_impl->SetDrawsContent(true); | 1388 delegated_renderer_layer_impl->SetDrawsContent(true); |
| 1389 | 1389 |
| 1390 // Contributing render pass is offset by a transform and holds a quad that |
| 1391 // covers it entirely. |
| 1390 RenderPassList delegated_render_passes; | 1392 RenderPassList delegated_render_passes; |
| 1391 // pass2 is just the size of the quad. It contributes to |pass1| with a | 1393 // pass2 is just the size of the quad. It contributes to |pass1| with a |
| 1392 // translation of (11,0). | 1394 // translation of (211,300). |
| 1393 RenderPassId pass2_id = | 1395 RenderPassId pass2_id = |
| 1394 delegated_renderer_layer_impl->FirstContributingRenderPassId(); | 1396 delegated_renderer_layer_impl->FirstContributingRenderPassId(); |
| 1395 TestRenderPass* pass2 = | 1397 TestRenderPass* pass2 = AddRenderPass(&delegated_render_passes, |
| 1396 AddRenderPass(&delegated_render_passes, pass2_id, quad_rect, transform); | 1398 pass2_id, |
| 1397 AddQuad(pass2, gfx::Rect(quad_rect.size()), SK_ColorRED); | 1399 gfx::Rect(quad_screen_rect.size()), |
| 1400 transform); |
| 1401 AddQuad(pass2, gfx::Rect(quad_screen_rect.size()), SK_ColorRED); |
| 1398 // |pass1| covers the whole layer. | 1402 // |pass1| covers the whole layer. |
| 1399 RenderPassId pass1_id = RenderPassId(impl.root_layer()->id(), 0); | 1403 RenderPassId pass1_id = RenderPassId(impl.root_layer()->id(), 0); |
| 1400 TestRenderPass* pass1 = AddRenderPass(&delegated_render_passes, | 1404 TestRenderPass* pass1 = AddRenderPass(&delegated_render_passes, |
| 1401 pass1_id, | 1405 pass1_id, |
| 1402 gfx::Rect(layer_size), | 1406 gfx::Rect(layer_size), |
| 1403 gfx::Transform()); | 1407 gfx::Transform()); |
| 1404 AddRenderPassQuad(pass1, pass2, 0, FilterOperations(), transform); | 1408 AddRenderPassQuad(pass1, pass2, 0, FilterOperations(), transform); |
| 1405 delegated_renderer_layer_impl->SetFrameDataForRenderPasses( | 1409 delegated_renderer_layer_impl->SetFrameDataForRenderPasses( |
| 1406 1.f, &delegated_render_passes); | 1410 1.f, &delegated_render_passes); |
| 1407 | 1411 |
| 1408 impl.CalcDrawProps(viewport_size); | 1412 impl.CalcDrawProps(viewport_size); |
| 1409 | 1413 |
| 1410 // The |quad_rect| translated by the |transform|. | |
| 1411 gfx::Rect quad_screen_rect = quad_rect + gfx::Vector2d(11, 0); | |
| 1412 | |
| 1413 { | 1414 { |
| 1414 SCOPED_TRACE("No occlusion"); | 1415 SCOPED_TRACE("No occlusion"); |
| 1415 gfx::Rect occluded; | 1416 gfx::Rect occluded; |
| 1416 | 1417 |
| 1417 { | 1418 { |
| 1418 SCOPED_TRACE("Root render pass"); | 1419 SCOPED_TRACE("Root render pass"); |
| 1419 impl.AppendQuadsForPassWithOcclusion( | 1420 impl.AppendQuadsForPassWithOcclusion( |
| 1420 delegated_renderer_layer_impl, pass1_id, occluded); | 1421 delegated_renderer_layer_impl, pass1_id, occluded); |
| 1421 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), | 1422 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), |
| 1422 quad_screen_rect); | 1423 quad_screen_rect); |
| 1423 ASSERT_EQ(1u, impl.quad_list().size()); | 1424 ASSERT_EQ(1u, impl.quad_list().size()); |
| 1424 EXPECT_EQ(DrawQuad::RENDER_PASS, impl.quad_list()[0]->material); | 1425 EXPECT_EQ(DrawQuad::RENDER_PASS, impl.quad_list()[0]->material); |
| 1425 } | 1426 } |
| 1426 { | 1427 { |
| 1427 SCOPED_TRACE("Contributing render pass"); | 1428 SCOPED_TRACE("Contributing render pass"); |
| 1428 impl.AppendQuadsForPassWithOcclusion( | 1429 impl.AppendQuadsForPassWithOcclusion( |
| 1429 delegated_renderer_layer_impl, pass2_id, occluded); | 1430 delegated_renderer_layer_impl, pass2_id, occluded); |
| 1430 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), | 1431 LayerTestCommon::VerifyQuadsExactlyCoverRect( |
| 1431 gfx::Rect(quad_rect.size())); | 1432 impl.quad_list(), gfx::Rect(quad_screen_rect.size())); |
| 1432 ASSERT_EQ(1u, impl.quad_list().size()); | 1433 ASSERT_EQ(1u, impl.quad_list().size()); |
| 1433 EXPECT_EQ(DrawQuad::SOLID_COLOR, impl.quad_list()[0]->material); | 1434 EXPECT_EQ(DrawQuad::SOLID_COLOR, impl.quad_list()[0]->material); |
| 1434 } | 1435 } |
| 1435 } | 1436 } |
| 1436 | 1437 |
| 1437 { | 1438 { |
| 1438 SCOPED_TRACE("Full occlusion"); | 1439 SCOPED_TRACE("Full occlusion"); |
| 1439 { | 1440 { |
| 1440 gfx::Rect occluded(delegated_renderer_layer_impl->visible_content_rect()); | 1441 gfx::Rect occluded(delegated_renderer_layer_impl->visible_content_rect()); |
| 1441 | 1442 |
| 1442 SCOPED_TRACE("Root render pass"); | 1443 SCOPED_TRACE("Root render pass"); |
| 1443 impl.AppendQuadsForPassWithOcclusion( | 1444 impl.AppendQuadsForPassWithOcclusion( |
| 1444 delegated_renderer_layer_impl, pass1_id, occluded); | 1445 delegated_renderer_layer_impl, pass1_id, occluded); |
| 1445 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), | 1446 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), |
| 1446 gfx::Rect()); | 1447 gfx::Rect()); |
| 1447 EXPECT_EQ(impl.quad_list().size(), 0u); | 1448 EXPECT_EQ(impl.quad_list().size(), 0u); |
| 1448 } | 1449 } |
| 1449 { | 1450 { |
| 1450 gfx::Rect occluded(delegated_renderer_layer_impl->visible_content_rect()); | 1451 gfx::Rect occluded(delegated_renderer_layer_impl->visible_content_rect()); |
| 1451 // Move the occlusion to where it is in the contributing surface. | |
| 1452 occluded -= quad_rect.OffsetFromOrigin(); | |
| 1453 | 1452 |
| 1454 SCOPED_TRACE("Contributing render pass"); | 1453 SCOPED_TRACE("Contributing render pass"); |
| 1455 impl.AppendQuadsForPassWithOcclusion( | 1454 impl.AppendQuadsForPassWithOcclusion( |
| 1456 delegated_renderer_layer_impl, pass2_id, occluded); | 1455 delegated_renderer_layer_impl, pass2_id, occluded); |
| 1457 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), | 1456 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), |
| 1458 gfx::Rect()); | 1457 gfx::Rect()); |
| 1459 EXPECT_EQ(impl.quad_list().size(), 0u); | 1458 EXPECT_EQ(impl.quad_list().size(), 0u); |
| 1460 } | 1459 } |
| 1461 } | 1460 } |
| 1462 | 1461 |
| 1463 { | 1462 { |
| 1464 SCOPED_TRACE("Partial occlusion"); | 1463 SCOPED_TRACE("Partial occlusion"); |
| 1465 { | 1464 { |
| 1466 gfx::Rect occluded(0, 0, 500, 1000); | 1465 gfx::Rect occlusion_in_root_target(0, 0, 500, 1000); |
| 1467 | 1466 |
| 1468 SCOPED_TRACE("Root render pass"); | 1467 SCOPED_TRACE("Root render pass"); |
| 1469 impl.AppendQuadsForPassWithOcclusion( | 1468 impl.AppendQuadsForPassWithOcclusion( |
| 1470 delegated_renderer_layer_impl, pass1_id, occluded); | 1469 delegated_renderer_layer_impl, pass1_id, occlusion_in_root_target); |
| 1471 size_t partially_occluded_count = 0; | 1470 size_t partially_occluded_count = 0; |
| 1472 LayerTestCommon::VerifyQuadsCoverRectWithOcclusion( | 1471 LayerTestCommon::VerifyQuadsAreOccluded(impl.quad_list(), |
| 1473 impl.quad_list(), | 1472 occlusion_in_root_target, |
| 1474 quad_screen_rect, | 1473 &partially_occluded_count); |
| 1475 occluded, | |
| 1476 &partially_occluded_count); | |
| 1477 // The layer outputs one quad, which is partially occluded. | 1474 // The layer outputs one quad, which is partially occluded. |
| 1478 EXPECT_EQ(1u, impl.quad_list().size()); | 1475 EXPECT_EQ(1u, impl.quad_list().size()); |
| 1479 EXPECT_EQ(1u, partially_occluded_count); | 1476 EXPECT_EQ(1u, partially_occluded_count); |
| 1480 } | 1477 } |
| 1481 { | 1478 { |
| 1482 gfx::Rect occluded(0, 0, 500, 1000); | 1479 gfx::Rect occlusion_in_root_target(0, 0, 500, 1000); |
| 1483 // Move the occlusion to where it is in the contributing surface. | 1480 // Move the occlusion to where it is in the contributing surface. |
| 1484 occluded -= quad_rect.OffsetFromOrigin() + gfx::Vector2d(11, 0); | 1481 gfx::Rect occlusion_in_target_of_delegated_quad = |
| 1482 occlusion_in_root_target - quad_screen_rect.OffsetFromOrigin(); |
| 1485 | 1483 |
| 1486 SCOPED_TRACE("Contributing render pass"); | 1484 SCOPED_TRACE("Contributing render pass"); |
| 1487 impl.AppendQuadsForPassWithOcclusion( | 1485 impl.AppendQuadsForPassWithOcclusion( |
| 1488 delegated_renderer_layer_impl, pass2_id, occluded); | 1486 delegated_renderer_layer_impl, pass2_id, occlusion_in_root_target); |
| 1489 size_t partially_occluded_count = 0; | 1487 size_t partially_occluded_count = 0; |
| 1490 LayerTestCommon::VerifyQuadsCoverRectWithOcclusion( | 1488 LayerTestCommon::VerifyQuadsAreOccluded( |
| 1491 impl.quad_list(), | 1489 impl.quad_list(), |
| 1492 gfx::Rect(quad_rect.size()), | 1490 occlusion_in_target_of_delegated_quad, |
| 1493 occluded, | |
| 1494 &partially_occluded_count); | 1491 &partially_occluded_count); |
| 1495 // The layer outputs one quad, which is partially occluded. | 1492 // The layer outputs one quad, which is partially occluded. |
| 1496 EXPECT_EQ(1u, impl.quad_list().size()); | 1493 EXPECT_EQ(1u, impl.quad_list().size()); |
| 1497 EXPECT_EQ(1u, partially_occluded_count); | 1494 EXPECT_EQ(1u, partially_occluded_count); |
| 1498 // The quad in the contributing surface is at (211,300) in the root. | 1495 // The quad in the contributing surface is at (211,300) in the root. |
| 1499 // The occlusion extends to 500 in the x-axis, pushing the left of the | 1496 // The occlusion extends to 500 in the x-axis, pushing the left of the |
| 1500 // visible part of the quad to 500 - 211 = 300 - 11 inside the quad. | 1497 // visible part of the quad to 500 - 211 = 300 - 11 inside the quad. |
| 1501 EXPECT_EQ(gfx::Rect(300 - 11, 0, 100 + 11, 500).ToString(), | 1498 EXPECT_EQ(gfx::Rect(300 - 11, 0, 100 + 11, 500).ToString(), |
| 1502 impl.quad_list()[0]->visible_rect.ToString()); | 1499 impl.quad_list()[0]->visible_rect.ToString()); |
| 1503 } | 1500 } |
| 1504 } | 1501 { |
| 1505 { | 1502 gfx::Rect occlusion_in_root_target(0, 0, 500, 1000); |
| 1506 gfx::Rect occluded(0, 0, 500, 1000); | 1503 // Move the occlusion to where it is in the contributing surface. |
| 1507 // Move the occlusion to where it is in the contributing surface. | 1504 gfx::Rect occlusion_in_target_of_delegated_quad = |
| 1508 occluded -= quad_rect.OffsetFromOrigin() + gfx::Vector2d(11, 0); | 1505 occlusion_in_root_target - quad_screen_rect.OffsetFromOrigin(); |
| 1509 | 1506 |
| 1510 SCOPED_TRACE("Contributing render pass with transformed root"); | 1507 SCOPED_TRACE("Contributing render pass with transformed root"); |
| 1511 | 1508 |
| 1512 delegated_renderer_layer_impl->SetTransform(transform); | 1509 gfx::Transform layer_transform; |
| 1513 impl.CalcDrawProps(viewport_size); | 1510 layer_transform.Translate(11.0, 0.0); |
| 1511 delegated_renderer_layer_impl->SetTransform(layer_transform); |
| 1514 | 1512 |
| 1515 impl.AppendQuadsForPassWithOcclusion( | 1513 occlusion_in_target_of_delegated_quad += gfx::Vector2d(11, 0); |
| 1516 delegated_renderer_layer_impl, pass2_id, occluded); | 1514 |
| 1517 size_t partially_occluded_count = 0; | 1515 impl.CalcDrawProps(viewport_size); |
| 1518 LayerTestCommon::VerifyQuadsCoverRectWithOcclusion( | 1516 |
| 1519 impl.quad_list(), | 1517 impl.AppendQuadsForPassWithOcclusion( |
| 1520 gfx::Rect(quad_rect.size()), | 1518 delegated_renderer_layer_impl, pass2_id, occlusion_in_root_target); |
| 1521 occluded, | 1519 size_t partially_occluded_count = 0; |
| 1522 &partially_occluded_count); | 1520 LayerTestCommon::VerifyQuadsAreOccluded( |
| 1523 // The layer outputs one quad, which is partially occluded. | 1521 impl.quad_list(), |
| 1524 EXPECT_EQ(1u, impl.quad_list().size()); | 1522 occlusion_in_target_of_delegated_quad, |
| 1525 EXPECT_EQ(1u, partially_occluded_count); | 1523 &partially_occluded_count); |
| 1526 // The quad in the contributing surface is at (222,300) in the transformed | 1524 // The layer outputs one quad, which is partially occluded. |
| 1527 // root. The occlusion extends to 500 in the x-axis, pushing the left of the | 1525 EXPECT_EQ(1u, impl.quad_list().size()); |
| 1528 // visible part of the quad to 500 - 222 = 300 - 22 inside the quad. | 1526 EXPECT_EQ(1u, partially_occluded_count); |
| 1529 EXPECT_EQ(gfx::Rect(300 - 22, 0, 100 + 22, 500).ToString(), | 1527 // The quad in the contributing surface is at (222,300) in the transformed |
| 1530 impl.quad_list()[0]->visible_rect.ToString()); | 1528 // root. The occlusion extends to 500 in the x-axis, pushing the left of |
| 1529 // the visible part of the quad to 500 - 222 = 300 - 22 inside the quad. |
| 1530 EXPECT_EQ(gfx::Rect(300 - 22, 0, 100 + 22, 500).ToString(), |
| 1531 impl.quad_list()[0]->visible_rect.ToString()); |
| 1532 } |
| 1531 } | 1533 } |
| 1532 } | 1534 } |
| 1533 | 1535 |
| 1534 TEST_F(DelegatedRendererLayerImplTest, PushPropertiesTo) { | 1536 TEST_F(DelegatedRendererLayerImplTest, PushPropertiesTo) { |
| 1535 gfx::Size layer_size(1000, 1000); | 1537 gfx::Size layer_size(1000, 1000); |
| 1536 | 1538 |
| 1537 scoped_ptr<FakeDelegatedRendererLayerImpl> delegated_renderer_layer_impl = | 1539 scoped_ptr<FakeDelegatedRendererLayerImpl> delegated_renderer_layer_impl = |
| 1538 FakeDelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 5); | 1540 FakeDelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 5); |
| 1539 delegated_renderer_layer_impl->SetBounds(layer_size); | 1541 delegated_renderer_layer_impl->SetBounds(layer_size); |
| 1540 delegated_renderer_layer_impl->SetContentBounds(layer_size); | 1542 delegated_renderer_layer_impl->SetContentBounds(layer_size); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1554 scoped_ptr<DelegatedRendererLayerImpl> other_layer = | 1556 scoped_ptr<DelegatedRendererLayerImpl> other_layer = |
| 1555 DelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 6); | 1557 DelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 6); |
| 1556 | 1558 |
| 1557 delegated_renderer_layer_impl->PushPropertiesTo(other_layer.get()); | 1559 delegated_renderer_layer_impl->PushPropertiesTo(other_layer.get()); |
| 1558 | 1560 |
| 1559 EXPECT_EQ(0.5f, other_layer->inverse_device_scale_factor()); | 1561 EXPECT_EQ(0.5f, other_layer->inverse_device_scale_factor()); |
| 1560 } | 1562 } |
| 1561 | 1563 |
| 1562 } // namespace | 1564 } // namespace |
| 1563 } // namespace cc | 1565 } // namespace cc |
| OLD | NEW |