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

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

Issue 2035543003: cc: Fix for synced property main thread updates with MFBA. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: test Created 4 years, 6 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
« cc/base/synced_property.h ('K') | « cc/base/synced_property.h ('k') | 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 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/layer_tree_host.h" 5 #include "cc/trees/layer_tree_host.h"
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/memory/weak_ptr.h" 8 #include "base/memory/weak_ptr.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
11 #include "cc/base/completion_event.h"
11 #include "cc/input/main_thread_scrolling_reason.h" 12 #include "cc/input/main_thread_scrolling_reason.h"
12 #include "cc/layers/layer.h" 13 #include "cc/layers/layer.h"
13 #include "cc/layers/layer_impl.h" 14 #include "cc/layers/layer_impl.h"
14 #include "cc/layers/picture_layer.h" 15 #include "cc/layers/picture_layer.h"
15 #include "cc/scheduler/begin_frame_source.h" 16 #include "cc/scheduler/begin_frame_source.h"
16 #include "cc/test/fake_content_layer_client.h" 17 #include "cc/test/fake_content_layer_client.h"
17 #include "cc/test/fake_layer_tree_host_client.h" 18 #include "cc/test/fake_layer_tree_host_client.h"
18 #include "cc/test/fake_picture_layer.h" 19 #include "cc/test/fake_picture_layer.h"
19 #include "cc/test/fake_picture_layer_impl.h" 20 #include "cc/test/fake_picture_layer_impl.h"
20 #include "cc/test/geometry_test_utils.h" 21 #include "cc/test/geometry_test_utils.h"
(...skipping 1485 matching lines...) Expand 10 before | Expand all | Expand 10 after
1506 1507
1507 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyLayer) { 1508 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyLayer) {
1508 RunTest(CompositorMode::THREADED, false); 1509 RunTest(CompositorMode::THREADED, false);
1509 } 1510 }
1510 1511
1511 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) { 1512 TEST_F(LayerTreeHostScrollTestLayerStructureChange, ScrollDestroyWholeTree) {
1512 scroll_destroy_whole_tree_ = true; 1513 scroll_destroy_whole_tree_ = true;
1513 RunTest(CompositorMode::THREADED, false); 1514 RunTest(CompositorMode::THREADED, false);
1514 } 1515 }
1515 1516
1517 class LayerTreeHostScrollTestScrollMFBA : public LayerTreeHostScrollTest {
1518 public:
1519 LayerTreeHostScrollTestScrollMFBA()
1520 : initial_scroll_(10, 20),
1521 second_scroll_(40, 5),
1522 scroll_amount_(2, -1),
1523 num_commits_(0),
1524 num_scrolls_(0) {}
1525
1526 void InitializeSettings(LayerTreeSettings* settings) override {
1527 settings->main_frame_before_activation_enabled = true;
1528 }
1529
1530 void BeginTest() override {
1531 outer_viewport_container_layer_id_ = layer_tree_host()
1532 ->outer_viewport_scroll_layer()
1533 ->scroll_clip_layer()
1534 ->id();
1535 layer_tree_host()->outer_viewport_scroll_layer()->SetScrollOffset(
1536 initial_scroll_);
1537 PostSetNeedsCommitToMainThread();
1538 }
1539
1540 void StartCommitOnImpl() override {
1541 switch (num_commits_) {
1542 case 0:
1543 PostSetNeedsCommitToMainThread();
1544 break;
1545 case 1:
1546 PostSetNeedsCommitToMainThread();
1547 // Block activation after second commit until third commit is ready.
1548 GetProxyImplForTest()->BlockNotifyReadyToActivateForTesting(true);
1549 break;
1550 case 2:
1551 // Unblock activation after third commit is ready.
1552 GetProxyImplForTest()->BlockNotifyReadyToActivateForTesting(false);
1553 break;
1554 }
1555 num_commits_++;
1556 }
1557
1558 void UpdateLayerTreeHost() override {
1559 Layer* scroll_layer = layer_tree_host()->outer_viewport_scroll_layer();
1560 switch (layer_tree_host()->source_frame_number()) {
1561 case 0:
1562 EXPECT_VECTOR_EQ(initial_scroll_, scroll_layer->scroll_offset());
1563 break;
1564 case 1:
1565 EXPECT_VECTOR_EQ(
1566 gfx::ScrollOffsetWithDelta(initial_scroll_, scroll_amount_),
1567 scroll_layer->scroll_offset());
1568
1569 // Pretend like Javascript updated the scroll position itself.
1570 scroll_layer->SetScrollOffset(second_scroll_);
1571 break;
1572 case 2:
1573 // Third frame does not see a scroll delta because we only did one
1574 // scroll for the second and third frames.
1575 EXPECT_VECTOR_EQ(second_scroll_, scroll_layer->scroll_offset());
1576 break;
1577 }
1578 }
1579
1580 void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
1581 LayerImpl* root = impl->active_tree()->root_layer();
1582 LayerImpl* scroll_layer = impl->OuterViewportScrollLayer();
1583 EXPECT_VECTOR_EQ(gfx::Vector2d(), ScrollDelta(scroll_layer));
1584
1585 scroll_layer->SetScrollClipLayer(outer_viewport_container_layer_id_);
1586 scroll_layer->SetBounds(
1587 gfx::Size(root->bounds().width() + 100, root->bounds().height() + 100));
1588 scroll_layer->ScrollBy(scroll_amount_);
1589
1590 switch (num_commits_) {
1591 case 1:
1592 EXPECT_VECTOR_EQ(initial_scroll_, ScrollTreeForLayer(scroll_layer)
1593 ->GetScrollOffsetBaseForTesting(
1594 scroll_layer->id()));
1595 EXPECT_VECTOR_EQ(scroll_amount_, ScrollDelta(scroll_layer));
1596
1597 break;
1598 case 2:
1599 EXPECT_VECTOR_EQ(second_scroll_, ScrollTreeForLayer(scroll_layer)
1600 ->GetScrollOffsetBaseForTesting(
1601 scroll_layer->id()));
1602 EXPECT_VECTOR_EQ(scroll_amount_, ScrollDelta(scroll_layer));
1603 break;
1604 case 3:
1605 EXPECT_VECTOR_EQ(second_scroll_, ScrollTreeForLayer(scroll_layer)
1606 ->GetScrollOffsetBaseForTesting(
1607 scroll_layer->id()));
1608 // Two scrolls haven't been consumed by the main thread.
1609 EXPECT_VECTOR_EQ(scroll_amount_, ScrollDelta(scroll_layer));
1610 EndTest();
1611 break;
1612 }
1613 }
1614
1615 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta,
1616 const gfx::Vector2dF& outer_delta,
1617 const gfx::Vector2dF& elastic_overscroll_delta,
1618 float scale,
1619 float top_controls_delta) override {
1620 num_scrolls_++;
1621 }
1622
1623 void AfterTest() override {
1624 EXPECT_EQ(3, num_commits_);
1625 EXPECT_EQ(1, num_scrolls_);
1626 }
1627
1628 private:
1629 gfx::ScrollOffset initial_scroll_;
1630 gfx::ScrollOffset second_scroll_;
1631 gfx::Vector2dF scroll_amount_;
1632 int num_commits_;
1633 int num_scrolls_;
1634 int outer_viewport_container_layer_id_;
1635 };
1636
1637 MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollMFBA);
1638
1516 } // namespace 1639 } // namespace
1517 } // namespace cc 1640 } // namespace cc
OLDNEW
« cc/base/synced_property.h ('K') | « cc/base/synced_property.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698