Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: cc/trees/layer_tree_host_impl_unittest.cc

Issue 955233002: cc: Fix scrollbar animation tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 scrollbar animation should be scheduled about 20ms from
1641 // now.
1642 host_impl_->ScrollBegin(gfx::Point(), InputHandler::WHEEL);
1643 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2dF(0, 5));
1644 EXPECT_FALSE(did_request_animate_);
1645 EXPECT_TRUE(did_request_redraw_);
1646 did_request_redraw_ = false;
1647 EXPECT_EQ(base::TimeDelta(), requested_animation_delay_);
1648 EXPECT_TRUE(animation_task_.Equals(base::Closure()));
1649
1650 host_impl_->ScrollEnd();
1651 EXPECT_FALSE(did_request_animate_);
1652 EXPECT_FALSE(did_request_redraw_);
1653 EXPECT_EQ(base::TimeDelta::FromMilliseconds(20),
1654 requested_animation_delay_);
1655 EXPECT_FALSE(animation_task_.Equals(base::Closure()));
1656
1657 fake_now += requested_animation_delay_;
1658 requested_animation_delay_ = base::TimeDelta();
1659 animation_task_.Run();
1660 animation_task_ = base::Closure();
1661 EXPECT_TRUE(did_request_animate_);
1662 did_request_animate_ = false;
1663 EXPECT_FALSE(did_request_redraw_);
1664
1665 // After the scrollbar animation begins, we should start getting redraws.
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 scrollbar animation.
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 // Scrollbar animation is not triggered unnecessarily.
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 // Changing page scale triggers scrollbar animation.
1702 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 4.f);
1703 host_impl_->SetPageScaleOnActiveTree(1.1f);
1704 EXPECT_FALSE(did_request_animate_);
1705 EXPECT_FALSE(did_request_redraw_);
1706 EXPECT_EQ(base::TimeDelta::FromMilliseconds(20),
1707 requested_animation_delay_);
1708 EXPECT_FALSE(animation_task_.Equals(base::Closure()));
1709 requested_animation_delay_ = base::TimeDelta();
1710 animation_task_ = base::Closure();
1711 }
1712 };
1713
1714 TEST_F(LayerTreeHostImplTestScrollbarAnimation, LinearFade) {
1715 RunTest(LayerTreeSettings::LINEAR_FADE);
1695 } 1716 }
1696 1717
1697 TEST_F(LayerTreeHostImplTest, ScrollbarFadePinchZoomScrollbars) { 1718 TEST_F(LayerTreeHostImplTestScrollbarAnimation, Thinning) {
1698 LayerTreeSettings settings; 1719 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);
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 } 1720 }
1753 1721
1754 void LayerTreeHostImplTest::SetupMouseMoveAtWithDeviceScale( 1722 void LayerTreeHostImplTest::SetupMouseMoveAtWithDeviceScale(
1755 float device_scale_factor) { 1723 float device_scale_factor) {
1756 LayerTreeSettings settings; 1724 LayerTreeSettings settings;
1757 settings.scrollbar_fade_delay_ms = 500; 1725 settings.scrollbar_fade_delay_ms = 500;
1758 settings.scrollbar_fade_duration_ms = 300; 1726 settings.scrollbar_fade_duration_ms = 300;
1759 settings.scrollbar_animator = LayerTreeSettings::THINNING; 1727 settings.scrollbar_animator = LayerTreeSettings::THINNING;
1760 1728
1761 gfx::Size viewport_size(300, 200); 1729 gfx::Size viewport_size(300, 200);
(...skipping 6713 matching lines...) Expand 10 before | Expand all | Expand 10 after
8475 // surface. 8443 // surface.
8476 EXPECT_EQ(0, num_lost_surfaces_); 8444 EXPECT_EQ(0, num_lost_surfaces_);
8477 host_impl_->DidLoseOutputSurface(); 8445 host_impl_->DidLoseOutputSurface();
8478 EXPECT_EQ(1, num_lost_surfaces_); 8446 EXPECT_EQ(1, num_lost_surfaces_);
8479 host_impl_->DidLoseOutputSurface(); 8447 host_impl_->DidLoseOutputSurface();
8480 EXPECT_LE(1, num_lost_surfaces_); 8448 EXPECT_LE(1, num_lost_surfaces_);
8481 } 8449 }
8482 8450
8483 } // namespace 8451 } // namespace
8484 } // namespace cc 8452 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698