blob: 887f1b401e6add231a477def91d0067c166cd513 [file] [log] [blame]
[email protected]c0dd24c2012-08-30 23:25:271// 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]a8461d82012-10-16 21:11:145#include "cc/texture_layer.h"
[email protected]c0dd24c2012-08-30 23:25:276
[email protected]d50c6862012-10-23 02:08:317#include "cc/layer_tree_host.h"
[email protected]031ccfff2012-10-26 00:57:388#include "cc/single_thread_proxy.h"
[email protected]586d51ed2012-12-07 20:31:459#include "cc/test/fake_impl_proxy.h"
[email protected]101441ce2012-10-16 01:45:0310#include "cc/test/fake_layer_tree_host_client.h"
[email protected]586d51ed2012-12-07 20:31:4511#include "cc/test/fake_layer_tree_host_impl.h"
12#include "cc/texture_layer_impl.h"
[email protected]61de5812012-11-08 07:03:4413#include "cc/thread.h"
[email protected]7f0c53db2012-10-02 00:23:1814#include "testing/gmock/include/gmock/gmock.h"
15#include "testing/gtest/include/gtest/gtest.h"
[email protected]c0dd24c2012-08-30 23:25:2716
[email protected]c0dd24c2012-08-30 23:25:2717using ::testing::Mock;
18using ::testing::_;
19using ::testing::AtLeast;
20using ::testing::AnyNumber;
21
[email protected]ba565742012-11-10 09:29:4822namespace cc {
[email protected]c0dd24c2012-08-30 23:25:2723namespace {
24
[email protected]96baf3e2012-10-22 23:09:5525class MockLayerImplTreeHost : public LayerTreeHost {
[email protected]c0dd24c2012-08-30 23:25:2726public:
[email protected]96baf3e2012-10-22 23:09:5527 MockLayerImplTreeHost()
28 : LayerTreeHost(&m_fakeClient, LayerTreeSettings())
[email protected]c0dd24c2012-08-30 23:25:2729 {
[email protected]61de5812012-11-08 07:03:4430 initialize(scoped_ptr<Thread>(NULL));
[email protected]c0dd24c2012-08-30 23:25:2731 }
32
33 MOCK_METHOD0(acquireLayerTextures, void());
[email protected]031ccfff2012-10-26 00:57:3834 MOCK_METHOD0(setNeedsCommit, void());
[email protected]c0dd24c2012-08-30 23:25:2735
36private:
[email protected]96baf3e2012-10-22 23:09:5537 FakeLayerImplTreeHostClient m_fakeClient;
[email protected]c0dd24c2012-08-30 23:25:2738};
39
40
[email protected]96baf3e2012-10-22 23:09:5541class TextureLayerTest : public testing::Test {
[email protected]0f077a52012-09-08 01:45:2442public:
[email protected]96baf3e2012-10-22 23:09:5543 TextureLayerTest()
[email protected]586d51ed2012-12-07 20:31:4544 : m_hostImpl(&m_proxy)
[email protected]0f077a52012-09-08 01:45:2445 {
46 }
47
[email protected]c0dd24c2012-08-30 23:25:2748protected:
49 virtual void SetUp()
50 {
[email protected]96baf3e2012-10-22 23:09:5551 m_layerTreeHost.reset(new MockLayerImplTreeHost);
[email protected]c0dd24c2012-08-30 23:25:2752 }
53
54 virtual void TearDown()
55 {
56 Mock::VerifyAndClearExpectations(m_layerTreeHost.get());
57 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AnyNumber());
[email protected]031ccfff2012-10-26 00:57:3858 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AnyNumber());
[email protected]c0dd24c2012-08-30 23:25:2759
60 m_layerTreeHost->setRootLayer(0);
[email protected]357b5172012-10-18 17:39:3361 m_layerTreeHost.reset();
[email protected]c0dd24c2012-08-30 23:25:2762 }
63
[email protected]96baf3e2012-10-22 23:09:5564 scoped_ptr<MockLayerImplTreeHost> m_layerTreeHost;
[email protected]586d51ed2012-12-07 20:31:4565 FakeImplProxy m_proxy;
66 FakeLayerTreeHostImpl m_hostImpl;
[email protected]c0dd24c2012-08-30 23:25:2767};
68
[email protected]96baf3e2012-10-22 23:09:5569TEST_F(TextureLayerTest, syncImplWhenChangingTextureId)
[email protected]c0dd24c2012-08-30 23:25:2770{
[email protected]96baf3e2012-10-22 23:09:5571 scoped_refptr<TextureLayer> testLayer = TextureLayer::create(0);
[email protected]c0dd24c2012-08-30 23:25:2772 ASSERT_TRUE(testLayer);
73
74 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AnyNumber());
[email protected]031ccfff2012-10-26 00:57:3875 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AnyNumber());
[email protected]c0dd24c2012-08-30 23:25:2776 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]031ccfff2012-10-26 00:57:3881 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1));
[email protected]c0dd24c2012-08-30 23:25:2782 testLayer->setTextureId(1);
83 Mock::VerifyAndClearExpectations(m_layerTreeHost.get());
84
85 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AtLeast(1));
[email protected]031ccfff2012-10-26 00:57:3886 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1));
[email protected]c0dd24c2012-08-30 23:25:2787 testLayer->setTextureId(2);
88 Mock::VerifyAndClearExpectations(m_layerTreeHost.get());
89
90 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AtLeast(1));
[email protected]031ccfff2012-10-26 00:57:3891 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1));
[email protected]c0dd24c2012-08-30 23:25:2792 testLayer->setTextureId(0);
93 Mock::VerifyAndClearExpectations(m_layerTreeHost.get());
94}
95
[email protected]031ccfff2012-10-26 00:57:3896TEST_F(TextureLayerTest, syncImplWhenDrawing)
97{
[email protected]d0f98362012-11-01 23:02:3898 gfx::RectF dirtyRect(0, 0, 1, 1);
[email protected]031ccfff2012-10-26 00:57:3899
100 scoped_refptr<TextureLayer> testLayer = TextureLayer::create(0);
101 ASSERT_TRUE(testLayer);
102 scoped_ptr<TextureLayerImpl> implLayer;
[email protected]586d51ed2012-12-07 20:31:45103 implLayer = TextureLayerImpl::create(&m_hostImpl, 1);
[email protected]031ccfff2012-10-26 00:57:38104 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]031ccfff2012-10-26 00:57:38147}
148
[email protected]96baf3e2012-10-22 23:09:55149TEST_F(TextureLayerTest, syncImplWhenRemovingFromTree)
[email protected]c0dd24c2012-08-30 23:25:27150{
[email protected]96baf3e2012-10-22 23:09:55151 scoped_refptr<Layer> rootLayer = Layer::create();
[email protected]c0dd24c2012-08-30 23:25:27152 ASSERT_TRUE(rootLayer);
[email protected]96baf3e2012-10-22 23:09:55153 scoped_refptr<Layer> childLayer = Layer::create();
[email protected]c0dd24c2012-08-30 23:25:27154 ASSERT_TRUE(childLayer);
155 rootLayer->addChild(childLayer);
[email protected]96baf3e2012-10-22 23:09:55156 scoped_refptr<TextureLayer> testLayer = TextureLayer::create(0);
[email protected]c0dd24c2012-08-30 23:25:27157 ASSERT_TRUE(testLayer);
158 testLayer->setTextureId(0);
159 childLayer->addChild(testLayer);
160
161 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AnyNumber());
[email protected]031ccfff2012-10-26 00:57:38162 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AnyNumber());
[email protected]c0dd24c2012-08-30 23:25:27163 m_layerTreeHost->setRootLayer(rootLayer);
164 Mock::VerifyAndClearExpectations(m_layerTreeHost.get());
165
166 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0);
[email protected]031ccfff2012-10-26 00:57:38167 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1));
[email protected]c0dd24c2012-08-30 23:25:27168 testLayer->removeFromParent();
169 Mock::VerifyAndClearExpectations(m_layerTreeHost.get());
170
171 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0);
[email protected]031ccfff2012-10-26 00:57:38172 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1));
[email protected]c0dd24c2012-08-30 23:25:27173 childLayer->addChild(testLayer);
174 Mock::VerifyAndClearExpectations(m_layerTreeHost.get());
175
176 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0);
[email protected]031ccfff2012-10-26 00:57:38177 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1));
[email protected]c0dd24c2012-08-30 23:25:27178 testLayer->setTextureId(1);
179 Mock::VerifyAndClearExpectations(m_layerTreeHost.get());
180
181 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AtLeast(1));
[email protected]031ccfff2012-10-26 00:57:38182 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1));
[email protected]c0dd24c2012-08-30 23:25:27183 testLayer->removeFromParent();
184 Mock::VerifyAndClearExpectations(m_layerTreeHost.get());
185}
186
[email protected]ba565742012-11-10 09:29:48187} // namespace
188} // namespace cc