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

Unified Diff: cc/trees/layer_tree_host_unittest_scroll.cc

Issue 19106007: cc: Allow the main thread to cancel commits (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix scheduler tests Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: cc/trees/layer_tree_host_unittest_scroll.cc
diff --git a/cc/trees/layer_tree_host_unittest_scroll.cc b/cc/trees/layer_tree_host_unittest_scroll.cc
index c4140afbe6c1d07c82c329f09e1379c0c17b6cf3..6b7193608c3759483372299967422f7e20a8b7a8 100644
--- a/cc/trees/layer_tree_host_unittest_scroll.cc
+++ b/cc/trees/layer_tree_host_unittest_scroll.cc
@@ -72,8 +72,6 @@ class LayerTreeHostScrollTestScrollSimple : public LayerTreeHostScrollTest {
virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale)
OVERRIDE {
- gfx::Vector2d offset = layer_tree_host()->root_layer()->scroll_offset();
- layer_tree_host()->root_layer()->SetScrollOffset(offset + scroll_delta);
num_scrolls_++;
}
@@ -152,8 +150,6 @@ class LayerTreeHostScrollTestScrollMultipleRedraw
virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale)
OVERRIDE {
- gfx::Vector2d offset = layer_tree_host()->root_layer()->scroll_offset();
- layer_tree_host()->root_layer()->SetScrollOffset(offset + scroll_delta);
num_scrolls_++;
}
@@ -167,6 +163,182 @@ class LayerTreeHostScrollTestScrollMultipleRedraw
MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollMultipleRedraw);
+class LayerTreeHostScrollTestScrollAbortedCommit
+ : public LayerTreeHostScrollTest {
+ public:
+ LayerTreeHostScrollTestScrollAbortedCommit()
+ : initial_scroll_(50, 60),
+ impl_scroll_(-3, 2),
+ second_main_scroll_(14, -3),
+ impl_scale_(2.f),
+ num_will_begin_frames_(0),
+ num_did_begin_frames_(0),
+ num_will_commits_(0),
+ num_did_commits_(0),
+ num_impl_commits_(0),
+ num_impl_scrolls_(0) {}
+
+ virtual void BeginTest() OVERRIDE {
+ layer_tree_host()->root_layer()->SetScrollable(true);
+ layer_tree_host()->root_layer()->SetScrollOffset(initial_scroll_);
+ layer_tree_host()->root_layer()->SetBounds(gfx::Size(200, 200));
+ layer_tree_host()->root_layer()
+ ->SetMaxScrollOffset(gfx::Vector2d(100, 100));
+ layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.01f, 100.f);
+ PostSetNeedsCommitToMainThread();
+ }
+
+ virtual void WillBeginFrame() OVERRIDE {
+ num_will_begin_frames_++;
+ Layer* root = layer_tree_host()->root_layer();
+ switch (num_will_begin_frames_) {
+ case 1:
+ // This will not be aborted because of the initial prop changes.
+ EXPECT_EQ(0, num_impl_scrolls_);
+ EXPECT_EQ(0, layer_tree_host()->commit_number());
+ EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_);
+ EXPECT_EQ(1.f, layer_tree_host()->page_scale_factor());
+ break;
+ case 2:
+ // This commit will be aborted, and another commit will be
+ // initiated from the redraw.
+ EXPECT_EQ(1, num_impl_scrolls_);
+ EXPECT_EQ(1, layer_tree_host()->commit_number());
+ EXPECT_VECTOR_EQ(root->scroll_offset(),
+ initial_scroll_ + impl_scroll_);
+ EXPECT_EQ(impl_scale_, layer_tree_host()->page_scale_factor());
+ PostSetNeedsRedrawToMainThread();
+ break;
+ case 3:
+ // This commit will not be aborted because of the scroll change.
+ EXPECT_EQ(2, num_impl_scrolls_);
+ EXPECT_EQ(1, layer_tree_host()->commit_number());
+ EXPECT_VECTOR_EQ(root->scroll_offset(),
+ initial_scroll_ + impl_scroll_ + impl_scroll_);
+ EXPECT_EQ(impl_scale_ * impl_scale_,
+ layer_tree_host()->page_scale_factor());
+ root->SetScrollOffset(root->scroll_offset() + second_main_scroll_);
+ break;
+ case 4:
+ // This commit will also be aborted.
+ EXPECT_EQ(3, num_impl_scrolls_);
+ EXPECT_EQ(2, layer_tree_host()->commit_number());
+ EXPECT_VECTOR_EQ(root->scroll_offset(),
+ initial_scroll_ + impl_scroll_ + impl_scroll_ +
+ impl_scroll_ + second_main_scroll_);
+ // End the test by drawing to verify this commit is also aborted.
+ PostSetNeedsRedrawToMainThread();
+ break;
+ }
+ }
+
+ virtual void DidBeginFrame() OVERRIDE {
+ num_did_begin_frames_++;
+ }
+
+ virtual void WillCommit() OVERRIDE {
+ num_will_commits_++;
+ }
+
+ virtual void DidCommit() OVERRIDE {
+ num_did_commits_++;
+ }
+ virtual void BeginCommitOnThread(LayerTreeHostImpl* impl) OVERRIDE {
danakj 2013/07/17 20:53:24 nit: blank line above
enne (OOO) 2013/07/18 17:36:37 Done.
+ num_impl_commits_++;
+ }
+
+ virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
+ LayerImpl* root = impl->active_tree()->root_layer();
+
+ if (impl->active_tree()->source_frame_number() == 0 &&
+ impl->SourceAnimationFrameNumber() == 1) {
+ // First draw
+ EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d());
+ root->ScrollBy(impl_scroll_);
+ EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_scroll_);
+ EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_);
+
+ EXPECT_EQ(1.f, impl->active_tree()->page_scale_delta());
+ EXPECT_EQ(1.f, impl->active_tree()->total_page_scale_factor());
+ impl->active_tree()->SetPageScaleDelta(impl_scale_);
+ EXPECT_EQ(impl_scale_, impl->active_tree()->page_scale_delta());
+ EXPECT_EQ(impl_scale_, impl->active_tree()->total_page_scale_factor());
+
+ // To simplify the testing flow, don't redraw here, just commit.
+ impl->SetNeedsCommit();
+ } else if (impl->active_tree()->source_frame_number() == 0 &&
+ impl->SourceAnimationFrameNumber() == 2) {
+ // Test a second draw after an aborted commit.
+ // The scroll/scale values should be baked into the offset/scale factor
+ // since the main thread consumed but aborted the begin frame.
+ EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d());
+ root->ScrollBy(impl_scroll_);
+ EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_scroll_);
+ EXPECT_VECTOR_EQ(root->scroll_offset(), initial_scroll_ + impl_scroll_);
+
+ EXPECT_EQ(1.f, impl->active_tree()->page_scale_delta());
+ EXPECT_EQ(impl_scale_, impl->active_tree()->total_page_scale_factor());
+ impl->active_tree()->SetPageScaleDelta(impl_scale_);
+ EXPECT_EQ(impl_scale_, impl->active_tree()->page_scale_delta());
+ EXPECT_EQ(impl_scale_ * impl_scale_,
+ impl->active_tree()->total_page_scale_factor());
+
+ impl->SetNeedsCommit();
+ } else if (impl->active_tree()->source_frame_number() == 1 &&
+ impl->SourceAnimationFrameNumber() == 3) {
+ // Third draw after the second full commit.
+ EXPECT_EQ(root->ScrollDelta(), gfx::Vector2d());
+ root->ScrollBy(impl_scroll_);
+ impl->SetNeedsCommit();
+ EXPECT_VECTOR_EQ(root->ScrollDelta(), impl_scroll_);
+ EXPECT_VECTOR_EQ(
+ root->scroll_offset(),
+ initial_scroll_ + impl_scroll_ + impl_scroll_ + second_main_scroll_);
+ } else if (impl->active_tree()->source_frame_number() == 1 &&
+ impl->SourceAnimationFrameNumber() == 4) {
+ // Final draw after the second aborted commit.
+ EXPECT_VECTOR_EQ(root->ScrollDelta(), gfx::Vector2d());
+ EXPECT_VECTOR_EQ(root->scroll_offset(),
+ initial_scroll_ + impl_scroll_ + impl_scroll_ +
+ impl_scroll_ + second_main_scroll_);
+ EndTest();
+ }
+ }
+
+ virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale)
+ OVERRIDE {
+ // Emulate Blink:
+ layer_tree_host()->SetPageScaleFactorAndLimits(
+ layer_tree_host()->page_scale_factor() * scale, 0.01f, 100.f);
+ num_impl_scrolls_++;
+ }
+
+ virtual void AfterTest() OVERRIDE {
+ EXPECT_EQ(3, num_impl_scrolls_);
+ // Verify that the embedder sees aborted commits as real commits.
+ EXPECT_EQ(4, num_will_begin_frames_);
+ EXPECT_EQ(4, num_did_begin_frames_);
+ EXPECT_EQ(4, num_will_commits_);
+ EXPECT_EQ(4, num_did_commits_);
+ // ...but the compositor thread only sees two real ones.
+ EXPECT_EQ(2, num_impl_commits_);
+ }
+
+ private:
+ gfx::Vector2d initial_scroll_;
+ gfx::Vector2d impl_scroll_;
+ gfx::Vector2d second_main_scroll_;
+ float impl_scale_;
+ int num_will_begin_frames_;
+ int num_did_begin_frames_;
+ int num_will_commits_;
+ int num_did_commits_;
+ int num_impl_commits_;
+ int num_impl_scrolls_;
+};
+
+MULTI_THREAD_TEST_F(LayerTreeHostScrollTestScrollAbortedCommit);
danakj 2013/07/17 20:53:24 Does this fail in single thread?
enne (OOO) 2013/07/18 17:36:37 Yes. You can't get non-zero scroll deltas in the
+
class LayerTreeHostScrollTestFractionalScroll : public LayerTreeHostScrollTest {
public:
LayerTreeHostScrollTestFractionalScroll() : scroll_amount_(1.75, 0) {}
@@ -208,12 +380,6 @@ class LayerTreeHostScrollTestFractionalScroll : public LayerTreeHostScrollTest {
root->ScrollBy(scroll_amount_);
}
- virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale)
- OVERRIDE {
- gfx::Vector2d offset = layer_tree_host()->root_layer()->scroll_offset();
- layer_tree_host()->root_layer()->SetScrollOffset(offset + scroll_delta);
- }
-
virtual void AfterTest() OVERRIDE {}
private:
@@ -285,14 +451,18 @@ class LayerTreeHostScrollTestCaseWithChild : public LayerTreeHostScrollTest {
virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); }
+ virtual void WillCommit() OVERRIDE {
+ // Keep the test committing (otherwise the early out for no update
+ // will stall the test).
+ layer_tree_host()->SetNeedsCommit();
+ }
+
void DidScroll() {
final_scroll_offset_ = expected_scroll_layer_->scroll_offset();
}
virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale)
OVERRIDE {
- gfx::Vector2d offset = root_scroll_layer_->scroll_offset();
- root_scroll_layer_->SetScrollOffset(offset + scroll_delta);
num_scrolls_++;
}
@@ -644,8 +814,6 @@ class ImplSidePaintingScrollTestSimple : public ImplSidePaintingScrollTest {
virtual void ApplyScrollAndScale(gfx::Vector2d scroll_delta, float scale)
OVERRIDE {
- gfx::Vector2d offset = layer_tree_host()->root_layer()->scroll_offset();
- layer_tree_host()->root_layer()->SetScrollOffset(offset + scroll_delta);
num_scrolls_++;
}

Powered by Google App Engine
This is Rietveld 408576698