OLD | NEW |
---|---|
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/layer_tree_host_impl.h" | 5 #include "cc/trees/layer_tree_host_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 1545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1556 } | 1556 } |
1557 | 1557 |
1558 void SetCurrentPhysicalTimeTicksForTest(base::TimeTicks fake_now) { | 1558 void SetCurrentPhysicalTimeTicksForTest(base::TimeTicks fake_now) { |
1559 fake_current_physical_time_ = fake_now; | 1559 fake_current_physical_time_ = fake_now; |
1560 } | 1560 } |
1561 | 1561 |
1562 private: | 1562 private: |
1563 base::TimeTicks fake_current_physical_time_; | 1563 base::TimeTicks fake_current_physical_time_; |
1564 }; | 1564 }; |
1565 | 1565 |
1566 #define SETUP_LAYERS_FOR_SCROLLBAR_ANIMATION_TEST() \ | 1566 class LayerTreeHostImplTestScrollbarAnimation : public LayerTreeHostImplTest { |
1567 gfx::Size viewport_size(10, 10); \ | 1567 protected: |
1568 gfx::Size content_size(100, 100); \ | 1568 void SetupLayers(LayerTreeSettings settings) { |
1569 \ | 1569 gfx::Size viewport_size(10, 10); |
1570 LayerTreeHostImplOverridePhysicalTime* host_impl_override_time = \ | 1570 gfx::Size content_size(100, 100); |
1571 new LayerTreeHostImplOverridePhysicalTime(settings, this, &proxy_, \ | |
1572 shared_bitmap_manager_.get(), \ | |
1573 &stats_instrumentation_); \ | |
1574 host_impl_ = make_scoped_ptr(host_impl_override_time); \ | |
1575 host_impl_->InitializeRenderer(CreateOutputSurface()); \ | |
1576 host_impl_->SetViewportSize(viewport_size); \ | |
1577 \ | |
1578 scoped_ptr<LayerImpl> root = \ | |
1579 LayerImpl::Create(host_impl_->active_tree(), 1); \ | |
1580 root->SetBounds(viewport_size); \ | |
1581 \ | |
1582 scoped_ptr<LayerImpl> scroll = \ | |
1583 LayerImpl::Create(host_impl_->active_tree(), 2); \ | |
1584 scroll->SetScrollClipLayer(root->id()); \ | |
1585 scroll->PushScrollOffsetFromMainThread(gfx::ScrollOffset()); \ | |
1586 root->SetBounds(viewport_size); \ | |
1587 scroll->SetBounds(content_size); \ | |
1588 scroll->SetContentBounds(content_size); \ | |
1589 scroll->SetIsContainerForFixedPositionLayers(true); \ | |
1590 \ | |
1591 scoped_ptr<LayerImpl> contents = \ | |
1592 LayerImpl::Create(host_impl_->active_tree(), 3); \ | |
1593 contents->SetDrawsContent(true); \ | |
1594 contents->SetBounds(content_size); \ | |
1595 contents->SetContentBounds(content_size); \ | |
1596 \ | |
1597 scoped_ptr<SolidColorScrollbarLayerImpl> scrollbar = \ | |
1598 SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(), 4, \ | |
1599 VERTICAL, 10, 0, false, true); \ | |
1600 EXPECT_FLOAT_EQ(0.f, scrollbar->opacity()); \ | |
1601 \ | |
1602 scroll->AddChild(contents.Pass()); \ | |
1603 root->AddChild(scroll.Pass()); \ | |
1604 root->SetHasRenderSurface(true); \ | |
1605 scrollbar->SetScrollLayerAndClipLayerByIds(2, 1); \ | |
1606 root->AddChild(scrollbar.Pass()); \ | |
1607 \ | |
1608 host_impl_->active_tree()->SetRootLayer(root.Pass()); \ | |
1609 host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 1, 2, \ | |
1610 Layer::INVALID_ID); \ | |
1611 host_impl_->active_tree()->DidBecomeActive(); \ | |
1612 DrawFrame(); | |
1613 | 1571 |
1614 TEST_F(LayerTreeHostImplTest, ScrollbarLinearFadeScheduling) { | 1572 LayerTreeHostImplOverridePhysicalTime* host_impl_override_time = |
1615 LayerTreeSettings settings; | 1573 new LayerTreeHostImplOverridePhysicalTime(settings, this, &proxy_, |
1616 settings.scrollbar_animator = LayerTreeSettings::LINEAR_FADE; | 1574 shared_bitmap_manager_.get(), |
1617 settings.scrollbar_fade_delay_ms = 20; | 1575 &stats_instrumentation_); |
1618 settings.scrollbar_fade_duration_ms = 20; | 1576 host_impl_ = make_scoped_ptr(host_impl_override_time); |
1577 host_impl_->InitializeRenderer(CreateOutputSurface()); | |
1578 host_impl_->SetViewportSize(viewport_size); | |
1619 | 1579 |
1620 SETUP_LAYERS_FOR_SCROLLBAR_ANIMATION_TEST(); | 1580 scoped_ptr<LayerImpl> root = |
1581 LayerImpl::Create(host_impl_->active_tree(), 1); | |
1582 root->SetBounds(viewport_size); | |
1621 | 1583 |
1622 base::TimeTicks fake_now = gfx::FrameTime::Now(); | 1584 scoped_ptr<LayerImpl> scroll = |
1585 LayerImpl::Create(host_impl_->active_tree(), 2); | |
1586 scroll->SetScrollClipLayer(root->id()); | |
1587 scroll->PushScrollOffsetFromMainThread(gfx::ScrollOffset()); | |
1588 root->SetBounds(viewport_size); | |
1589 scroll->SetBounds(content_size); | |
1590 scroll->SetContentBounds(content_size); | |
1591 scroll->SetIsContainerForFixedPositionLayers(true); | |
1623 | 1592 |
1624 EXPECT_FALSE(did_request_animate_); | 1593 scoped_ptr<LayerImpl> contents = |
1625 EXPECT_FALSE(did_request_redraw_); | 1594 LayerImpl::Create(host_impl_->active_tree(), 3); |
1626 EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); | 1595 contents->SetDrawsContent(true); |
1627 EXPECT_TRUE(animation_task_.Equals(base::Closure())); | 1596 contents->SetBounds(content_size); |
1597 contents->SetContentBounds(content_size); | |
1628 | 1598 |
1629 // If no scroll happened during a scroll gesture, it should have no effect. | 1599 scoped_ptr<SolidColorScrollbarLayerImpl> scrollbar = |
1630 host_impl_->ScrollBegin(gfx::Point(), InputHandler::WHEEL); | 1600 SolidColorScrollbarLayerImpl::Create(host_impl_->active_tree(), 4, |
1631 host_impl_->ScrollEnd(); | 1601 VERTICAL, 10, 0, false, true); |
1632 EXPECT_FALSE(did_request_animate_); | 1602 EXPECT_FLOAT_EQ(0.f, scrollbar->opacity()); |
1633 EXPECT_FALSE(did_request_redraw_); | |
1634 EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); | |
1635 EXPECT_TRUE(animation_task_.Equals(base::Closure())); | |
1636 | 1603 |
1637 // After a scroll, a fade animation should be scheduled about 20ms from now. | 1604 scroll->AddChild(contents.Pass()); |
1638 host_impl_->ScrollBegin(gfx::Point(), InputHandler::WHEEL); | 1605 root->AddChild(scroll.Pass()); |
1639 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(0, 5)); | 1606 root->SetHasRenderSurface(true); |
1640 EXPECT_FALSE(did_request_animate_); | 1607 scrollbar->SetScrollLayerAndClipLayerByIds(2, 1); |
1641 EXPECT_TRUE(did_request_redraw_); | 1608 root->AddChild(scrollbar.Pass()); |
1642 did_request_redraw_ = false; | |
1643 EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); | |
1644 EXPECT_TRUE(animation_task_.Equals(base::Closure())); | |
1645 | 1609 |
1646 host_impl_->ScrollEnd(); | 1610 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
1647 EXPECT_FALSE(did_request_animate_); | 1611 host_impl_->active_tree()->SetViewportLayersFromIds(Layer::INVALID_ID, 1, 2, |
1648 EXPECT_FALSE(did_request_redraw_); | 1612 Layer::INVALID_ID); |
1649 EXPECT_EQ(base::TimeDelta::FromMilliseconds(20), requested_animation_delay_); | 1613 host_impl_->active_tree()->DidBecomeActive(); |
1650 EXPECT_FALSE(animation_task_.Equals(base::Closure())); | 1614 DrawFrame(); |
1615 } | |
1651 | 1616 |
1652 fake_now += requested_animation_delay_; | 1617 void RunTest(LayerTreeSettings::ScrollbarAnimator animator) { |
1653 requested_animation_delay_ = base::TimeDelta(); | 1618 LayerTreeSettings settings; |
1654 animation_task_.Run(); | 1619 settings.scrollbar_animator = animator; |
1655 animation_task_ = base::Closure(); | 1620 settings.scrollbar_fade_delay_ms = 20; |
1656 EXPECT_TRUE(did_request_animate_); | 1621 settings.scrollbar_fade_duration_ms = 20; |
1657 did_request_animate_ = false; | |
1658 EXPECT_FALSE(did_request_redraw_); | |
1659 | 1622 |
1660 // After the fade begins, we should start getting redraws instead of a | 1623 SetupLayers(settings); |
1661 // scheduled animation. | |
1662 host_impl_->Animate(fake_now); | |
1663 EXPECT_TRUE(did_request_animate_); | |
1664 did_request_animate_ = false; | |
1665 EXPECT_TRUE(did_request_redraw_); | |
1666 did_request_redraw_ = false; | |
1667 EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); | |
1668 EXPECT_TRUE(animation_task_.Equals(base::Closure())); | |
1669 | 1624 |
1670 // Setting the scroll offset outside a scroll should also cause the scrollbar | 1625 base::TimeTicks fake_now = gfx::FrameTime::Now(); |
1671 // to appear and to schedule a fade. | |
1672 host_impl_->InnerViewportScrollLayer()->PushScrollOffsetFromMainThread( | |
1673 gfx::ScrollOffset(5, 5)); | |
1674 EXPECT_FALSE(did_request_animate_); | |
1675 EXPECT_FALSE(did_request_redraw_); | |
1676 EXPECT_EQ(base::TimeDelta::FromMilliseconds(20), requested_animation_delay_); | |
1677 EXPECT_FALSE(animation_task_.Equals(base::Closure())); | |
1678 requested_animation_delay_ = base::TimeDelta(); | |
1679 animation_task_ = base::Closure(); | |
1680 | 1626 |
1681 // Unnecessarily Fade animation of solid color scrollbar is not triggered. | 1627 EXPECT_FALSE(did_request_animate_); |
1682 host_impl_->ScrollBegin(gfx::Point(), InputHandler::WHEEL); | 1628 EXPECT_FALSE(did_request_redraw_); |
1683 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(5, 0)); | 1629 EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); |
1684 EXPECT_FALSE(did_request_animate_); | 1630 EXPECT_TRUE(animation_task_.Equals(base::Closure())); |
1685 EXPECT_TRUE(did_request_redraw_); | |
1686 did_request_redraw_ = false; | |
1687 EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); | |
1688 EXPECT_TRUE(animation_task_.Equals(base::Closure())); | |
1689 | 1631 |
1690 host_impl_->ScrollEnd(); | 1632 // If no scroll happened during a scroll gesture, it should have no effect. |
1691 EXPECT_FALSE(did_request_animate_); | 1633 host_impl_->ScrollBegin(gfx::Point(), InputHandler::WHEEL); |
1692 EXPECT_FALSE(did_request_redraw_); | 1634 host_impl_->ScrollEnd(); |
1693 EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); | 1635 EXPECT_FALSE(did_request_animate_); |
1694 EXPECT_TRUE(animation_task_.Equals(base::Closure())); | 1636 EXPECT_FALSE(did_request_redraw_); |
1637 EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); | |
1638 EXPECT_TRUE(animation_task_.Equals(base::Closure())); | |
1639 | |
1640 // After a scroll, a fade animation should be scheduled about 20ms from now. | |
bokan
2015/03/02 22:49:06
Nit: this is no longer specifically for fade, plea
sunnyps
2015/03/03 20:47:09
Done.
| |
1641 host_impl_->ScrollBegin(gfx::Point(), InputHandler::WHEEL); | |
1642 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(0, 5)); | |
1643 EXPECT_FALSE(did_request_animate_); | |
1644 EXPECT_TRUE(did_request_redraw_); | |
1645 did_request_redraw_ = false; | |
1646 EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); | |
1647 EXPECT_TRUE(animation_task_.Equals(base::Closure())); | |
1648 | |
1649 host_impl_->ScrollEnd(); | |
1650 EXPECT_FALSE(did_request_animate_); | |
1651 EXPECT_FALSE(did_request_redraw_); | |
1652 EXPECT_EQ(base::TimeDelta::FromMilliseconds(20), | |
1653 requested_animation_delay_); | |
1654 EXPECT_FALSE(animation_task_.Equals(base::Closure())); | |
1655 | |
1656 fake_now += requested_animation_delay_; | |
1657 requested_animation_delay_ = base::TimeDelta(); | |
1658 animation_task_.Run(); | |
1659 animation_task_ = base::Closure(); | |
1660 EXPECT_TRUE(did_request_animate_); | |
1661 did_request_animate_ = false; | |
1662 EXPECT_FALSE(did_request_redraw_); | |
1663 | |
1664 // After the fade begins, we should start getting redraws instead of a | |
1665 // scheduled animation. | |
1666 host_impl_->Animate(fake_now); | |
1667 EXPECT_TRUE(did_request_animate_); | |
1668 did_request_animate_ = false; | |
1669 EXPECT_TRUE(did_request_redraw_); | |
1670 did_request_redraw_ = false; | |
1671 EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); | |
1672 EXPECT_TRUE(animation_task_.Equals(base::Closure())); | |
1673 | |
1674 // Setting the scroll offset outside a scroll should also cause the | |
1675 // scrollbar to appear and to schedule a fade. | |
1676 host_impl_->InnerViewportScrollLayer()->PushScrollOffsetFromMainThread( | |
1677 gfx::ScrollOffset(5, 5)); | |
1678 EXPECT_FALSE(did_request_animate_); | |
1679 EXPECT_FALSE(did_request_redraw_); | |
1680 EXPECT_EQ(base::TimeDelta::FromMilliseconds(20), | |
1681 requested_animation_delay_); | |
1682 EXPECT_FALSE(animation_task_.Equals(base::Closure())); | |
1683 requested_animation_delay_ = base::TimeDelta(); | |
1684 animation_task_ = base::Closure(); | |
1685 | |
1686 // Unnecessarily Fade animation of solid color scrollbar is not triggered. | |
ajuma
2015/02/26 15:30:45
While you're moving this: s/Unnecessarily/Unnecess
sunnyps
2015/03/02 19:19:07
Acknowledged.
sunnyps
2015/03/03 20:47:09
Done.
| |
1687 host_impl_->ScrollBegin(gfx::Point(), InputHandler::WHEEL); | |
1688 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(5, 0)); | |
1689 EXPECT_FALSE(did_request_animate_); | |
1690 EXPECT_TRUE(did_request_redraw_); | |
1691 did_request_redraw_ = false; | |
1692 EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); | |
1693 EXPECT_TRUE(animation_task_.Equals(base::Closure())); | |
1694 | |
1695 host_impl_->ScrollEnd(); | |
1696 EXPECT_FALSE(did_request_animate_); | |
1697 EXPECT_FALSE(did_request_redraw_); | |
1698 EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); | |
1699 EXPECT_TRUE(animation_task_.Equals(base::Closure())); | |
1700 } | |
1701 }; | |
1702 | |
1703 TEST_F(LayerTreeHostImplTestScrollbarAnimation, LinearFade) { | |
1704 RunTest(LayerTreeSettings::LINEAR_FADE); | |
1695 } | 1705 } |
1696 | 1706 |
1697 TEST_F(LayerTreeHostImplTest, ScrollbarFadePinchZoomScrollbars) { | 1707 TEST_F(LayerTreeHostImplTestScrollbarAnimation, Thinning) { |
1698 LayerTreeSettings settings; | 1708 RunTest(LayerTreeSettings::THINNING); |
1699 settings.scrollbar_animator = LayerTreeSettings::LINEAR_FADE; | |
1700 settings.scrollbar_fade_delay_ms = 20; | |
1701 settings.scrollbar_fade_duration_ms = 20; | |
1702 settings.use_pinch_zoom_scrollbars = true; | |
1703 | |
1704 SETUP_LAYERS_FOR_SCROLLBAR_ANIMATION_TEST(); | |
1705 | |
1706 base::TimeTicks fake_now = gfx::FrameTime::Now(); | |
1707 | |
1708 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 4.f); | |
1709 | |
1710 EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); | |
1711 EXPECT_FALSE(did_request_animate_); | |
1712 | |
1713 // If no scroll happened during a scroll gesture, it should have no effect. | |
1714 host_impl_->ScrollBegin(gfx::Point(), InputHandler::WHEEL); | |
1715 host_impl_->ScrollEnd(); | |
1716 EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); | |
1717 EXPECT_FALSE(did_request_animate_); | |
1718 EXPECT_TRUE(animation_task_.Equals(base::Closure())); | |
1719 | |
1720 // After a scroll, no fade animation should be scheduled. | |
1721 host_impl_->ScrollBegin(gfx::Point(), InputHandler::WHEEL); | |
1722 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(5, 0)); | |
1723 host_impl_->ScrollEnd(); | |
1724 did_request_redraw_ = false; | |
1725 EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); | |
1726 EXPECT_FALSE(did_request_animate_); | |
1727 requested_animation_delay_ = base::TimeDelta(); | |
1728 | |
1729 // We should not see any draw requests. | |
1730 fake_now += base::TimeDelta::FromMilliseconds(25); | |
1731 EXPECT_EQ(base::TimeDelta(), requested_animation_delay_); | |
1732 EXPECT_FALSE(did_request_animate_); | |
1733 | |
1734 // Make page scale > min so that subsequent scrolls will trigger fades. | |
1735 host_impl_->SetPageScaleOnActiveTree(1.1f); | |
ajuma
2015/02/26 15:30:45
Does this line have no effect on behavior? (As I u
sunnyps
2015/03/02 19:19:07
It seems the scrollbar fade animation is triggered
bokan
2015/03/02 22:49:06
That's not true, ScrollBy will activate the fade a
| |
1736 | |
1737 // After a scroll, a fade animation should be scheduled about 20ms from now. | |
1738 host_impl_->ScrollBegin(gfx::Point(), InputHandler::WHEEL); | |
1739 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(5, 0)); | |
1740 host_impl_->ScrollEnd(); | |
1741 did_request_redraw_ = false; | |
1742 EXPECT_LT(base::TimeDelta::FromMilliseconds(19), requested_animation_delay_); | |
1743 EXPECT_FALSE(did_request_animate_); | |
1744 requested_animation_delay_ = base::TimeDelta(); | |
1745 animation_task_.Run(); | |
1746 | |
1747 // After the fade begins, we should start getting redraws instead of a | |
1748 // scheduled animation. | |
1749 fake_now += base::TimeDelta::FromMilliseconds(25); | |
1750 host_impl_->Animate(fake_now); | |
1751 EXPECT_TRUE(did_request_animate_); | |
1752 } | 1709 } |
1753 | 1710 |
1754 void LayerTreeHostImplTest::SetupMouseMoveAtWithDeviceScale( | 1711 void LayerTreeHostImplTest::SetupMouseMoveAtWithDeviceScale( |
1755 float device_scale_factor) { | 1712 float device_scale_factor) { |
1756 LayerTreeSettings settings; | 1713 LayerTreeSettings settings; |
1757 settings.scrollbar_fade_delay_ms = 500; | 1714 settings.scrollbar_fade_delay_ms = 500; |
1758 settings.scrollbar_fade_duration_ms = 300; | 1715 settings.scrollbar_fade_duration_ms = 300; |
1759 settings.scrollbar_animator = LayerTreeSettings::THINNING; | 1716 settings.scrollbar_animator = LayerTreeSettings::THINNING; |
1760 | 1717 |
1761 gfx::Size viewport_size(300, 200); | 1718 gfx::Size viewport_size(300, 200); |
(...skipping 6713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8475 // surface. | 8432 // surface. |
8476 EXPECT_EQ(0, num_lost_surfaces_); | 8433 EXPECT_EQ(0, num_lost_surfaces_); |
8477 host_impl_->DidLoseOutputSurface(); | 8434 host_impl_->DidLoseOutputSurface(); |
8478 EXPECT_EQ(1, num_lost_surfaces_); | 8435 EXPECT_EQ(1, num_lost_surfaces_); |
8479 host_impl_->DidLoseOutputSurface(); | 8436 host_impl_->DidLoseOutputSurface(); |
8480 EXPECT_LE(1, num_lost_surfaces_); | 8437 EXPECT_LE(1, num_lost_surfaces_); |
8481 } | 8438 } |
8482 | 8439 |
8483 } // namespace | 8440 } // namespace |
8484 } // namespace cc | 8441 } // namespace cc |
OLD | NEW |