[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | a8461d8 | 2012-10-16 21:11:14 | [diff] [blame] | 5 | #include "cc/texture_layer.h" |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 6 | |
[email protected] | d50c686 | 2012-10-23 02:08:31 | [diff] [blame] | 7 | #include "cc/layer_tree_host.h" |
[email protected] | 031ccfff | 2012-10-26 00:57:38 | [diff] [blame] | 8 | #include "cc/single_thread_proxy.h" |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame^] | 9 | #include "cc/test/fake_impl_proxy.h" |
[email protected] | 101441ce | 2012-10-16 01:45:03 | [diff] [blame] | 10 | #include "cc/test/fake_layer_tree_host_client.h" |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame^] | 11 | #include "cc/test/fake_layer_tree_host_impl.h" |
| 12 | #include "cc/texture_layer_impl.h" |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 13 | #include "cc/thread.h" |
[email protected] | 7f0c53db | 2012-10-02 00:23:18 | [diff] [blame] | 14 | #include "testing/gmock/include/gmock/gmock.h" |
| 15 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 16 | |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 17 | using ::testing::Mock; |
| 18 | using ::testing::_; |
| 19 | using ::testing::AtLeast; |
| 20 | using ::testing::AnyNumber; |
| 21 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 22 | namespace cc { |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 23 | namespace { |
| 24 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 25 | class MockLayerImplTreeHost : public LayerTreeHost { |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 26 | public: |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 27 | MockLayerImplTreeHost() |
| 28 | : LayerTreeHost(&m_fakeClient, LayerTreeSettings()) |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 29 | { |
[email protected] | 61de581 | 2012-11-08 07:03:44 | [diff] [blame] | 30 | initialize(scoped_ptr<Thread>(NULL)); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | MOCK_METHOD0(acquireLayerTextures, void()); |
[email protected] | 031ccfff | 2012-10-26 00:57:38 | [diff] [blame] | 34 | MOCK_METHOD0(setNeedsCommit, void()); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 35 | |
| 36 | private: |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 37 | FakeLayerImplTreeHostClient m_fakeClient; |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 41 | class TextureLayerTest : public testing::Test { |
[email protected] | 0f077a5 | 2012-09-08 01:45:24 | [diff] [blame] | 42 | public: |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 43 | TextureLayerTest() |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame^] | 44 | : m_hostImpl(&m_proxy) |
[email protected] | 0f077a5 | 2012-09-08 01:45:24 | [diff] [blame] | 45 | { |
| 46 | } |
| 47 | |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 48 | protected: |
| 49 | virtual void SetUp() |
| 50 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 51 | m_layerTreeHost.reset(new MockLayerImplTreeHost); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | virtual void TearDown() |
| 55 | { |
| 56 | Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 57 | EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AnyNumber()); |
[email protected] | 031ccfff | 2012-10-26 00:57:38 | [diff] [blame] | 58 | EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AnyNumber()); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 59 | |
| 60 | m_layerTreeHost->setRootLayer(0); |
[email protected] | 357b517 | 2012-10-18 17:39:33 | [diff] [blame] | 61 | m_layerTreeHost.reset(); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 62 | } |
| 63 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 64 | scoped_ptr<MockLayerImplTreeHost> m_layerTreeHost; |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame^] | 65 | FakeImplProxy m_proxy; |
| 66 | FakeLayerTreeHostImpl m_hostImpl; |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 67 | }; |
| 68 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 69 | TEST_F(TextureLayerTest, syncImplWhenChangingTextureId) |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 70 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 71 | scoped_refptr<TextureLayer> testLayer = TextureLayer::create(0); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 72 | ASSERT_TRUE(testLayer); |
| 73 | |
| 74 | EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AnyNumber()); |
[email protected] | 031ccfff | 2012-10-26 00:57:38 | [diff] [blame] | 75 | EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AnyNumber()); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 76 | m_layerTreeHost->setRootLayer(testLayer); |
| 77 | Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 78 | EXPECT_EQ(testLayer->layerTreeHost(), m_layerTreeHost.get()); |
| 79 | |
| 80 | EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0); |
[email protected] | 031ccfff | 2012-10-26 00:57:38 | [diff] [blame] | 81 | EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1)); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 82 | testLayer->setTextureId(1); |
| 83 | Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 84 | |
| 85 | EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AtLeast(1)); |
[email protected] | 031ccfff | 2012-10-26 00:57:38 | [diff] [blame] | 86 | EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1)); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 87 | testLayer->setTextureId(2); |
| 88 | Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 89 | |
| 90 | EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AtLeast(1)); |
[email protected] | 031ccfff | 2012-10-26 00:57:38 | [diff] [blame] | 91 | EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1)); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 92 | testLayer->setTextureId(0); |
| 93 | Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 94 | } |
| 95 | |
[email protected] | 031ccfff | 2012-10-26 00:57:38 | [diff] [blame] | 96 | TEST_F(TextureLayerTest, syncImplWhenDrawing) |
| 97 | { |
[email protected] | d0f9836 | 2012-11-01 23:02:38 | [diff] [blame] | 98 | gfx::RectF dirtyRect(0, 0, 1, 1); |
[email protected] | 031ccfff | 2012-10-26 00:57:38 | [diff] [blame] | 99 | |
| 100 | scoped_refptr<TextureLayer> testLayer = TextureLayer::create(0); |
| 101 | ASSERT_TRUE(testLayer); |
| 102 | scoped_ptr<TextureLayerImpl> implLayer; |
[email protected] | 586d51ed | 2012-12-07 20:31:45 | [diff] [blame^] | 103 | implLayer = TextureLayerImpl::create(&m_hostImpl, 1); |
[email protected] | 031ccfff | 2012-10-26 00:57:38 | [diff] [blame] | 104 | ASSERT_TRUE(implLayer); |
| 105 | |
| 106 | EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AnyNumber()); |
| 107 | EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AnyNumber()); |
| 108 | m_layerTreeHost->setRootLayer(testLayer); |
| 109 | testLayer->setTextureId(1); |
| 110 | testLayer->setIsDrawable(true); |
| 111 | Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 112 | EXPECT_EQ(testLayer->layerTreeHost(), m_layerTreeHost.get()); |
| 113 | |
| 114 | EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(1); |
| 115 | EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(0); |
| 116 | testLayer->willModifyTexture(); |
| 117 | Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 118 | |
| 119 | EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0); |
| 120 | EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(1); |
| 121 | testLayer->setNeedsDisplayRect(dirtyRect); |
| 122 | Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 123 | |
| 124 | EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0); |
| 125 | EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(1); |
| 126 | testLayer->pushPropertiesTo(implLayer.get()); // fake commit |
| 127 | testLayer->setIsDrawable(false); |
| 128 | Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 129 | |
| 130 | // Verify that non-drawable layers don't signal the compositor, |
| 131 | // except for the first draw after last commit, which must acquire |
| 132 | // the texture. |
| 133 | EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(1); |
| 134 | EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(0); |
| 135 | testLayer->willModifyTexture(); |
| 136 | testLayer->setNeedsDisplayRect(dirtyRect); |
| 137 | testLayer->pushPropertiesTo(implLayer.get()); // fake commit |
| 138 | Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 139 | |
| 140 | // Second draw with layer in non-drawable state: no texture |
| 141 | // acquisition. |
| 142 | EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0); |
| 143 | EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(0); |
| 144 | testLayer->willModifyTexture(); |
| 145 | testLayer->setNeedsDisplayRect(dirtyRect); |
| 146 | Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
[email protected] | 031ccfff | 2012-10-26 00:57:38 | [diff] [blame] | 147 | } |
| 148 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 149 | TEST_F(TextureLayerTest, syncImplWhenRemovingFromTree) |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 150 | { |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 151 | scoped_refptr<Layer> rootLayer = Layer::create(); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 152 | ASSERT_TRUE(rootLayer); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 153 | scoped_refptr<Layer> childLayer = Layer::create(); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 154 | ASSERT_TRUE(childLayer); |
| 155 | rootLayer->addChild(childLayer); |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 156 | scoped_refptr<TextureLayer> testLayer = TextureLayer::create(0); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 157 | ASSERT_TRUE(testLayer); |
| 158 | testLayer->setTextureId(0); |
| 159 | childLayer->addChild(testLayer); |
| 160 | |
| 161 | EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AnyNumber()); |
[email protected] | 031ccfff | 2012-10-26 00:57:38 | [diff] [blame] | 162 | EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AnyNumber()); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 163 | m_layerTreeHost->setRootLayer(rootLayer); |
| 164 | Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 165 | |
| 166 | EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0); |
[email protected] | 031ccfff | 2012-10-26 00:57:38 | [diff] [blame] | 167 | EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1)); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 168 | testLayer->removeFromParent(); |
| 169 | Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 170 | |
| 171 | EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0); |
[email protected] | 031ccfff | 2012-10-26 00:57:38 | [diff] [blame] | 172 | EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1)); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 173 | childLayer->addChild(testLayer); |
| 174 | Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 175 | |
| 176 | EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0); |
[email protected] | 031ccfff | 2012-10-26 00:57:38 | [diff] [blame] | 177 | EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1)); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 178 | testLayer->setTextureId(1); |
| 179 | Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 180 | |
| 181 | EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AtLeast(1)); |
[email protected] | 031ccfff | 2012-10-26 00:57:38 | [diff] [blame] | 182 | EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1)); |
[email protected] | c0dd24c | 2012-08-30 23:25:27 | [diff] [blame] | 183 | testLayer->removeFromParent(); |
| 184 | Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); |
| 185 | } |
| 186 | |
[email protected] | ba56574 | 2012-11-10 09:29:48 | [diff] [blame] | 187 | } // namespace |
| 188 | } // namespace cc |