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.h" | 5 #include "cc/trees/layer_tree_host.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 7484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7495 DCHECK_EQ(hud->clip_tree_index(), root_layer->clip_tree_index()); | 7495 DCHECK_EQ(hud->clip_tree_index(), root_layer->clip_tree_index()); |
7496 DCHECK_EQ(hud->effect_tree_index(), root_layer->effect_tree_index()); | 7496 DCHECK_EQ(hud->effect_tree_index(), root_layer->effect_tree_index()); |
7497 DCHECK_EQ(hud->scroll_tree_index(), root_layer->scroll_tree_index()); | 7497 DCHECK_EQ(hud->scroll_tree_index(), root_layer->scroll_tree_index()); |
7498 } | 7498 } |
7499 | 7499 |
7500 void AfterTest() override {} | 7500 void AfterTest() override {} |
7501 }; | 7501 }; |
7502 | 7502 |
7503 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestHudLayerWithLayerLists); | 7503 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestHudLayerWithLayerLists); |
7504 | 7504 |
7505 // Verifies that LayerTreeHostClient does not receive frame acks from a released | |
7506 // CompositorFrameSink. | |
7507 class LayerTreeHostTestDiscardAckAfterRelease : public LayerTreeHostTest { | |
7508 protected: | |
7509 void BeginTest() override { | |
7510 PrepareNextCommit(); | |
7511 PostSetNeedsCommitToMainThread(); | |
7512 } | |
7513 | |
7514 void PrepareNextCommit() { | |
danakj
2017/04/19 14:36:28
nit: I think the standard way to write this would
Saman Sami
2017/04/19 15:00:15
Seems like SetNeedsCommit doesn't work on its own.
danakj
2017/04/19 15:23:01
Oh oh yeah, to redraw you need some damage. One wa
Saman Sami
2017/04/19 15:45:30
Done.
| |
7515 // Make some changes so we have something to commit. | |
7516 scoped_refptr<Layer> root = Layer::Create(); | |
7517 root->SetBounds(gfx::Size(10, 10)); | |
7518 layer_tree_host()->SetRootLayer(std::move(root)); | |
7519 commit_count_++; | |
7520 } | |
7521 | |
7522 void WillReceiveCompositorFrameAckOnThread( | |
7523 LayerTreeHostImpl* host_impl) override { | |
7524 // This method is called before ack is posted to main thread. This ensures | |
7525 // that WillReceiveCompositorFrameAck which we PostTask below will be called | |
7526 // before DidReceiveCompositorFrameAck. | |
7527 MainThreadTaskRunner()->PostTask( | |
7528 FROM_HERE, base::Bind(&LayerTreeHostTestDiscardAckAfterRelease:: | |
7529 WillReceiveCompositorFrameAck, | |
7530 base::Unretained(this))); | |
7531 } | |
7532 | |
7533 void WillReceiveCompositorFrameAck() { | |
7534 switch (commit_count_) { | |
7535 case 1: | |
7536 // For the first commit, don't release the CompositorFrameSink. We must | |
7537 // receive the ack later on. | |
7538 break; | |
7539 case 2: | |
7540 // Release the CompositorFrameSink for the second commit. We'll later | |
7541 // check that the ack is discarded. | |
7542 layer_tree_host()->SetVisible(false); | |
7543 layer_tree_host()->ReleaseCompositorFrameSink(); | |
7544 break; | |
7545 default: | |
7546 NOTREACHED(); | |
7547 } | |
7548 } | |
7549 | |
7550 void DidReceiveCompositorFrameAckOnThread( | |
7551 LayerTreeHostImpl* host_impl) override { | |
7552 // Since this method is called after ack is posted to main thread, we can be | |
7553 // sure that if the ack is not discarded, it will be definitely received | |
7554 // before we are in CheckFrameAck. | |
7555 MainThreadTaskRunner()->PostTask( | |
7556 FROM_HERE, | |
7557 base::Bind(&LayerTreeHostTestDiscardAckAfterRelease::CheckFrameAck, | |
7558 base::Unretained(this))); | |
7559 } | |
7560 | |
7561 void DidReceiveCompositorFrameAck() override { received_ack_ = true; } | |
7562 | |
7563 void CheckFrameAck() { | |
7564 switch (commit_count_) { | |
7565 case 1: | |
7566 // CompositorFrameSink was not released. We must receive the ack. | |
7567 EXPECT_TRUE(received_ack_); | |
7568 PrepareNextCommit(); | |
7569 break; | |
7570 case 2: | |
7571 // CompositorFrameSink was released. The ack must be discarded. | |
7572 EXPECT_FALSE(received_ack_); | |
7573 EndTest(); | |
7574 break; | |
7575 default: | |
7576 NOTREACHED(); | |
7577 } | |
7578 received_ack_ = false; | |
7579 } | |
7580 | |
7581 void AfterTest() override {} | |
7582 | |
7583 private: | |
7584 bool received_ack_ = false; | |
7585 int commit_count_ = 0; | |
7586 }; | |
7587 | |
7588 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDiscardAckAfterRelease); | |
7589 | |
7505 } // namespace | 7590 } // namespace |
7506 } // namespace cc | 7591 } // namespace cc |
OLD | NEW |