Chromium Code Reviews| 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/trees/occlusion_tracker.h" | 5 #include "cc/trees/occlusion_tracker.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "cc/base/math_util.h" | 9 #include "cc/base/math_util.h" |
| 10 #include "cc/layers/layer.h" | 10 #include "cc/layers/layer.h" |
| (...skipping 1522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1533 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); | 1533 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); |
| 1534 | 1534 |
| 1535 this->DestroyLayers(); | 1535 this->DestroyLayers(); |
| 1536 } | 1536 } |
| 1537 } | 1537 } |
| 1538 }; | 1538 }; |
| 1539 | 1539 |
| 1540 ALL_OCCLUSIONTRACKER_TEST( | 1540 ALL_OCCLUSIONTRACKER_TEST( |
| 1541 OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter); | 1541 OcclusionTrackerTestDontOccludePixelsNeededForBackgroundFilter); |
| 1542 | 1542 |
| 1543 class OcclusionTrackerTestDontOccludePixelsNeededForDropShadowBackgroundFilter | |
| 1544 : public OcclusionTrackerTest { | |
| 1545 protected: | |
| 1546 explicit OcclusionTrackerTestDontOccludePixelsNeededForDropShadowBackgroundFil ter( | |
| 1547 bool opaque_layers) | |
| 1548 : OcclusionTrackerTest(opaque_layers) {} | |
| 1549 void RunMyTest() override { | |
| 1550 gfx::Transform scale_by_half; | |
| 1551 scale_by_half.Scale(0.5, 0.5); | |
| 1552 | |
| 1553 FilterOperations filters; | |
| 1554 filters.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(10, 10), | |
| 1555 5, SK_ColorBLACK)); | |
| 1556 | |
| 1557 enum Direction { | |
| 1558 LEFT, | |
| 1559 RIGHT, | |
| 1560 TOP, | |
| 1561 BOTTOM, | |
| 1562 LAST_DIRECTION = BOTTOM, | |
| 1563 }; | |
| 1564 | |
| 1565 for (int i = 0; i <= LAST_DIRECTION; ++i) { | |
| 1566 SCOPED_TRACE(i); | |
| 1567 | |
| 1568 // Make a 50x50 filtered surface that is adjacent to occluding layers | |
| 1569 // which are above it in the z-order in various configurations. The | |
| 1570 // surface is scaled to test that the pixel moving is done in the target | |
| 1571 // space, where the background filter is applied. | |
| 1572 TestContentLayerImpl* parent = this->CreateRoot( | |
| 1573 this->identity_matrix, gfx::PointF(), gfx::Size(200, 200)); | |
| 1574 LayerImpl* filtered_surface = this->CreateDrawingLayer( | |
| 1575 parent, scale_by_half, gfx::PointF(50.f, 50.f), gfx::Size(100, 100), | |
| 1576 false); | |
| 1577 filtered_surface->test_properties()->background_filters = filters; | |
| 1578 gfx::Rect occlusion_rect; | |
| 1579 switch (i) { | |
| 1580 case LEFT: | |
| 1581 occlusion_rect = gfx::Rect(0, 0, 50, 200); | |
| 1582 break; | |
| 1583 case RIGHT: | |
| 1584 occlusion_rect = gfx::Rect(100, 0, 50, 200); | |
|
enne (OOO)
2016/07/06 18:20:30
Shouldn't an adjacent occlusion layer be (150, 0)
jbroman
2016/07/06 18:42:48
That would also work. This matches what the test a
enne (OOO)
2016/07/06 19:50:00
I'm just saying the comment above that this is adj
jbroman
2016/07/06 20:26:06
Turns out it _is_ adjacent, because it's only 50x5
| |
| 1585 break; | |
| 1586 case TOP: | |
| 1587 occlusion_rect = gfx::Rect(0, 0, 200, 50); | |
| 1588 break; | |
| 1589 case BOTTOM: | |
| 1590 occlusion_rect = gfx::Rect(0, 100, 200, 50); | |
| 1591 break; | |
| 1592 } | |
| 1593 | |
| 1594 LayerImpl* occluding_layer = this->CreateDrawingLayer( | |
| 1595 parent, this->identity_matrix, gfx::PointF(occlusion_rect.origin()), | |
| 1596 occlusion_rect.size(), true); | |
| 1597 occluding_layer->test_properties()->force_render_surface = false; | |
| 1598 this->CalcDrawEtc(parent); | |
| 1599 | |
| 1600 TestOcclusionTrackerWithClip occlusion(gfx::Rect(0, 0, 200, 200)); | |
| 1601 | |
| 1602 // This layer occludes pixels directly beside the filtered_surface. | |
| 1603 // Because filtered surface blends pixels in a radius, it will need to see | |
| 1604 // some of the pixels (up to radius far) underneath the occluding layers. | |
| 1605 this->VisitLayer(occluding_layer, &occlusion); | |
| 1606 | |
| 1607 EXPECT_EQ(occlusion_rect.ToString(), | |
| 1608 occlusion.occlusion_from_inside_target().ToString()); | |
| 1609 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); | |
| 1610 | |
| 1611 this->VisitLayer(filtered_surface, &occlusion); | |
| 1612 | |
| 1613 // The occlusion is used fully inside the surface. | |
| 1614 gfx::Rect occlusion_inside_surface = | |
| 1615 occlusion_rect - gfx::Vector2d(50, 50); | |
| 1616 EXPECT_TRUE(occlusion.occlusion_from_inside_target().IsEmpty()); | |
| 1617 EXPECT_EQ(occlusion_inside_surface.ToString(), | |
| 1618 occlusion.occlusion_from_outside_target().ToString()); | |
| 1619 | |
| 1620 // The surface has a background filter, so it needs pixels that are | |
| 1621 // currently considered occluded in order to be drawn. So the pixels it | |
| 1622 // needs should be removed some the occluded area so that when we get to | |
|
enne (OOO)
2016/07/06 18:20:30
grammar?
jbroman
2016/07/06 18:42:48
Copied from the previous unit test. Would you like
enne (OOO)
2016/07/06 19:49:59
Yes, please!
jbroman
2016/07/06 20:26:06
Reworded in a way that's hopefully clearer.
| |
| 1623 // the parent they are drawn. | |
| 1624 this->VisitContributingSurface(filtered_surface, &occlusion); | |
| 1625 this->EnterLayer(parent, &occlusion); | |
| 1626 | |
| 1627 gfx::Rect expected_occlusion; | |
| 1628 switch (i) { | |
| 1629 case LEFT: | |
| 1630 // The right half of the occlusion is close enough to cast a shadow | |
| 1631 // that would be visible in the background filter. The shadow reaches | |
| 1632 // 3*5 + 10 = 25 pixels to the right. | |
| 1633 expected_occlusion = gfx::Rect(0, 0, 25, 200); | |
| 1634 break; | |
| 1635 case RIGHT: | |
| 1636 // The shadow spreads 3*5 - 10 = 5 pixels to the left, so the | |
| 1637 // occlusion must recede by 5 to account for that. | |
| 1638 expected_occlusion = gfx::Rect(105, 0, 45, 200); | |
| 1639 break; | |
| 1640 case TOP: | |
| 1641 // Similar to LEFT. | |
| 1642 expected_occlusion = gfx::Rect(0, 0, 200, 25); | |
| 1643 break; | |
| 1644 case BOTTOM: | |
| 1645 // Similar to RIGHT. | |
| 1646 expected_occlusion = gfx::Rect(0, 105, 200, 45); | |
| 1647 break; | |
| 1648 } | |
| 1649 | |
| 1650 EXPECT_EQ(expected_occlusion.ToString(), | |
| 1651 occlusion.occlusion_from_inside_target().ToString()); | |
| 1652 EXPECT_TRUE(occlusion.occlusion_from_outside_target().IsEmpty()); | |
| 1653 | |
| 1654 this->DestroyLayers(); | |
| 1655 } | |
| 1656 } | |
| 1657 }; | |
| 1658 | |
| 1659 ALL_OCCLUSIONTRACKER_TEST( | |
| 1660 OcclusionTrackerTestDontOccludePixelsNeededForDropShadowBackgroundFilter); | |
| 1661 | |
| 1543 class OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice | 1662 class OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice |
| 1544 : public OcclusionTrackerTest { | 1663 : public OcclusionTrackerTest { |
| 1545 protected: | 1664 protected: |
| 1546 explicit OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice( | 1665 explicit OcclusionTrackerTestTwoBackgroundFiltersReduceOcclusionTwice( |
| 1547 bool opaque_layers) | 1666 bool opaque_layers) |
| 1548 : OcclusionTrackerTest(opaque_layers) {} | 1667 : OcclusionTrackerTest(opaque_layers) {} |
| 1549 void RunMyTest() override { | 1668 void RunMyTest() override { |
| 1550 gfx::Transform scale_by_half; | 1669 gfx::Transform scale_by_half; |
| 1551 scale_by_half.Scale(0.5, 0.5); | 1670 scale_by_half.Scale(0.5, 0.5); |
| 1552 | 1671 |
| (...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2515 EXPECT_EQ(gfx::Rect(), | 2634 EXPECT_EQ(gfx::Rect(), |
| 2516 occlusion.UnoccludedSurfaceContentRect( | 2635 occlusion.UnoccludedSurfaceContentRect( |
| 2517 surface, gfx::Rect(80, 70, 50, 50))); | 2636 surface, gfx::Rect(80, 70, 50, 50))); |
| 2518 } | 2637 } |
| 2519 }; | 2638 }; |
| 2520 | 2639 |
| 2521 ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestUnoccludedSurfaceQuery) | 2640 ALL_OCCLUSIONTRACKER_TEST(OcclusionTrackerTestUnoccludedSurfaceQuery) |
| 2522 | 2641 |
| 2523 } // namespace | 2642 } // namespace |
| 2524 } // namespace cc | 2643 } // namespace cc |
| OLD | NEW |