OLD | NEW |
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/layers/texture_layer.h" | 5 #include "cc/layers/texture_layer.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/run_loop.h" |
10 #include "cc/layers/texture_layer_client.h" | 11 #include "cc/layers/texture_layer_client.h" |
11 #include "cc/layers/texture_layer_impl.h" | 12 #include "cc/layers/texture_layer_impl.h" |
12 #include "cc/test/fake_impl_proxy.h" | 13 #include "cc/test/fake_impl_proxy.h" |
13 #include "cc/test/fake_layer_tree_host_client.h" | 14 #include "cc/test/fake_layer_tree_host_client.h" |
14 #include "cc/test/fake_layer_tree_host_impl.h" | 15 #include "cc/test/fake_layer_tree_host_impl.h" |
15 #include "cc/test/layer_test_common.h" | 16 #include "cc/test/layer_test_common.h" |
16 #include "cc/test/layer_tree_test.h" | 17 #include "cc/test/layer_tree_test.h" |
17 #include "cc/trees/layer_tree_host.h" | 18 #include "cc/trees/layer_tree_host.h" |
18 #include "cc/trees/layer_tree_impl.h" | 19 #include "cc/trees/layer_tree_impl.h" |
19 #include "cc/trees/single_thread_proxy.h" | 20 #include "cc/trees/single_thread_proxy.h" |
20 #include "gpu/GLES2/gl2extchromium.h" | 21 #include "gpu/GLES2/gl2extchromium.h" |
21 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
23 | 24 |
24 using ::testing::Mock; | 25 using ::testing::Mock; |
25 using ::testing::_; | 26 using ::testing::_; |
26 using ::testing::AtLeast; | 27 using ::testing::AtLeast; |
27 using ::testing::AnyNumber; | 28 using ::testing::AnyNumber; |
| 29 using ::testing::InvokeWithoutArgs; |
28 | 30 |
29 namespace cc { | 31 namespace cc { |
30 namespace { | 32 namespace { |
31 | 33 |
32 class MockLayerTreeHost : public LayerTreeHost { | 34 class MockLayerTreeHost : public LayerTreeHost { |
33 public: | 35 public: |
34 explicit MockLayerTreeHost(LayerTreeHostClient* client) | 36 explicit MockLayerTreeHost(LayerTreeHostClient* client) |
35 : LayerTreeHost(client, LayerTreeSettings()) { | 37 : LayerTreeHost(client, LayerTreeSettings()) { |
36 Initialize(NULL); | 38 Initialize(NULL); |
37 } | 39 } |
38 | 40 |
39 MOCK_METHOD0(AcquireLayerTextures, void()); | 41 MOCK_METHOD0(AcquireLayerTextures, void()); |
40 MOCK_METHOD0(SetNeedsCommit, void()); | 42 MOCK_METHOD0(SetNeedsCommit, void()); |
41 MOCK_METHOD1(StartRateLimiter, void(WebKit::WebGraphicsContext3D* context)); | 43 MOCK_METHOD1(StartRateLimiter, void(WebKit::WebGraphicsContext3D* context)); |
42 MOCK_METHOD1(StopRateLimiter, void(WebKit::WebGraphicsContext3D* context)); | 44 MOCK_METHOD1(StopRateLimiter, void(WebKit::WebGraphicsContext3D* context)); |
43 }; | 45 }; |
44 | 46 |
| 47 class FakeTextureLayerClient : public TextureLayerClient { |
| 48 public: |
| 49 FakeTextureLayerClient() |
| 50 : context_(TestWebGraphicsContext3D::CreateShared()), |
| 51 texture_(0), |
| 52 mailbox_changed_(true) {} |
| 53 |
| 54 virtual unsigned PrepareTexture() OVERRIDE { |
| 55 return texture_; |
| 56 } |
| 57 |
| 58 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { |
| 59 return context_.get(); |
| 60 } |
| 61 |
| 62 virtual bool PrepareTextureMailbox(TextureMailbox* mailbox, |
| 63 bool use_shared_memory) OVERRIDE { |
| 64 if (!mailbox_changed_) |
| 65 return false; |
| 66 |
| 67 *mailbox = mailbox_; |
| 68 mailbox_changed_ = false; |
| 69 return true; |
| 70 } |
| 71 |
| 72 void set_texture(unsigned texture) { |
| 73 texture_ = texture; |
| 74 } |
| 75 |
| 76 void set_mailbox(const TextureMailbox& mailbox) { |
| 77 mailbox_ = mailbox; |
| 78 mailbox_changed_ = true; |
| 79 } |
| 80 |
| 81 private: |
| 82 scoped_ptr<TestWebGraphicsContext3D> context_; |
| 83 unsigned texture_; |
| 84 TextureMailbox mailbox_; |
| 85 bool mailbox_changed_; |
| 86 DISALLOW_COPY_AND_ASSIGN(FakeTextureLayerClient); |
| 87 }; |
| 88 |
| 89 class MockMailboxCallback { |
| 90 public: |
| 91 MOCK_METHOD3(Release, void(const std::string& mailbox, |
| 92 unsigned sync_point, |
| 93 bool lost_resource)); |
| 94 MOCK_METHOD3(Release2, void(base::SharedMemory* shared_memory, |
| 95 unsigned sync_point, |
| 96 bool lost_resource)); |
| 97 }; |
| 98 |
| 99 struct CommonMailboxObjects { |
| 100 CommonMailboxObjects() |
| 101 : mailbox_name1_(64, '1'), |
| 102 mailbox_name2_(64, '2'), |
| 103 sync_point1_(1), |
| 104 sync_point2_(2), |
| 105 shared_memory_(new base::SharedMemory) { |
| 106 release_mailbox1_ = base::Bind(&MockMailboxCallback::Release, |
| 107 base::Unretained(&mock_callback_), |
| 108 mailbox_name1_); |
| 109 release_mailbox2_ = base::Bind(&MockMailboxCallback::Release, |
| 110 base::Unretained(&mock_callback_), |
| 111 mailbox_name2_); |
| 112 gpu::Mailbox m1; |
| 113 m1.SetName(reinterpret_cast<const int8*>(mailbox_name1_.data())); |
| 114 mailbox1_ = TextureMailbox(m1, release_mailbox1_, sync_point1_); |
| 115 gpu::Mailbox m2; |
| 116 m2.SetName(reinterpret_cast<const int8*>(mailbox_name2_.data())); |
| 117 mailbox2_ = TextureMailbox(m2, release_mailbox2_, sync_point2_); |
| 118 |
| 119 gfx::Size size(128, 128); |
| 120 EXPECT_TRUE(shared_memory_->CreateAndMapAnonymous(4 * size.GetArea())); |
| 121 release_mailbox3_ = base::Bind(&MockMailboxCallback::Release2, |
| 122 base::Unretained(&mock_callback_), |
| 123 shared_memory_.get()); |
| 124 mailbox3_ = TextureMailbox(shared_memory_.get(), size, release_mailbox3_); |
| 125 } |
| 126 |
| 127 std::string mailbox_name1_; |
| 128 std::string mailbox_name2_; |
| 129 MockMailboxCallback mock_callback_; |
| 130 TextureMailbox::ReleaseCallback release_mailbox1_; |
| 131 TextureMailbox::ReleaseCallback release_mailbox2_; |
| 132 TextureMailbox::ReleaseCallback release_mailbox3_; |
| 133 TextureMailbox mailbox1_; |
| 134 TextureMailbox mailbox2_; |
| 135 TextureMailbox mailbox3_; |
| 136 unsigned sync_point1_; |
| 137 unsigned sync_point2_; |
| 138 scoped_ptr<base::SharedMemory> shared_memory_; |
| 139 }; |
| 140 |
45 class TextureLayerTest : public testing::Test { | 141 class TextureLayerTest : public testing::Test { |
46 public: | 142 public: |
47 TextureLayerTest() | 143 TextureLayerTest() |
48 : fake_client_( | 144 : fake_client_( |
49 FakeLayerTreeHostClient(FakeLayerTreeHostClient::DIRECT_3D)), | 145 FakeLayerTreeHostClient(FakeLayerTreeHostClient::DIRECT_3D)), |
50 host_impl_(&proxy_) {} | 146 host_impl_(&proxy_) {} |
51 | 147 |
52 protected: | 148 protected: |
53 virtual void SetUp() { | 149 virtual void SetUp() { |
54 layer_tree_host_.reset(new MockLayerTreeHost(&fake_client_)); | 150 layer_tree_host_.reset(new MockLayerTreeHost(&fake_client_)); |
55 } | 151 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
| 152 layer_tree_host_->SetViewportSize(gfx::Size(10, 10)); |
| 153 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 154 } |
56 | 155 |
57 virtual void TearDown() { | 156 virtual void TearDown() { |
58 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 157 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
59 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber()); | 158 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber()); |
60 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); | 159 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
61 | 160 |
62 layer_tree_host_->SetRootLayer(NULL); | 161 layer_tree_host_->SetRootLayer(NULL); |
63 layer_tree_host_.reset(); | 162 layer_tree_host_.reset(); |
64 } | 163 } |
65 | 164 |
66 scoped_ptr<MockLayerTreeHost> layer_tree_host_; | 165 scoped_ptr<MockLayerTreeHost> layer_tree_host_; |
67 FakeImplProxy proxy_; | 166 FakeImplProxy proxy_; |
68 FakeLayerTreeHostClient fake_client_; | 167 FakeLayerTreeHostClient fake_client_; |
69 FakeLayerTreeHostImpl host_impl_; | 168 FakeLayerTreeHostImpl host_impl_; |
70 }; | 169 }; |
71 | 170 |
72 TEST_F(TextureLayerTest, SyncImplWhenChangingTextureId) { | 171 TEST_F(TextureLayerTest, SyncImplWhenClearingTexture) { |
73 scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(NULL); | 172 FakeTextureLayerClient client; |
| 173 scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(&client); |
74 ASSERT_TRUE(test_layer.get()); | 174 ASSERT_TRUE(test_layer.get()); |
| 175 test_layer->SetIsDrawable(true); |
| 176 test_layer->SetBounds(gfx::Size(10, 10)); |
75 | 177 |
76 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber()); | 178 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
77 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); | 179 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
78 layer_tree_host_->SetRootLayer(test_layer); | 180 layer_tree_host_->SetRootLayer(test_layer); |
79 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 181 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
80 EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get()); | 182 EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get()); |
81 | 183 |
| 184 // Clearing the texture before we gave one should not sync. |
| 185 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
| 186 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
| 187 test_layer->ClearTexture(); |
| 188 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 189 |
| 190 // Give a texture to the layer through the client. |
82 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); | 191 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
83 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | 192 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
84 test_layer->SetTextureId(1); | 193 client.set_texture(client.Context3d()->createTexture()); |
| 194 test_layer->SetNeedsDisplay(); |
| 195 // Force a commit. |
| 196 layer_tree_host_->Composite(base::TimeTicks()); |
85 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 197 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
86 | 198 |
| 199 // Clearing the texture should sync. |
87 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AtLeast(1)); | 200 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AtLeast(1)); |
88 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | 201 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
89 test_layer->SetTextureId(2); | 202 test_layer->ClearTexture(); |
90 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 203 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
91 | 204 |
92 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AtLeast(1)); | 205 // But only once. |
| 206 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
| 207 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
| 208 test_layer->ClearTexture(); |
| 209 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 210 |
| 211 // Force a commit to give another texture. |
93 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | 212 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
94 test_layer->SetTextureId(0); | 213 test_layer->SetNeedsDisplay(); |
| 214 layer_tree_host_->Composite(base::TimeTicks()); |
| 215 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 216 |
| 217 // Make undrawable and commit. |
| 218 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
| 219 test_layer->SetIsDrawable(false); |
| 220 layer_tree_host_->Composite(base::TimeTicks()); |
| 221 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 222 |
| 223 // Clearing textures should not sync. |
| 224 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
| 225 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
| 226 test_layer->ClearTexture(); |
95 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 227 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
96 } | 228 } |
97 | 229 |
98 TEST_F(TextureLayerTest, SyncImplWhenDrawing) { | 230 TEST_F(TextureLayerTest, SyncImplWhenClearingMailbox) { |
99 gfx::RectF dirty_rect(0.f, 0.f, 1.f, 1.f); | 231 CommonMailboxObjects mailboxes; |
100 | 232 FakeTextureLayerClient client; |
101 scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(NULL); | 233 scoped_refptr<TextureLayer> test_layer = |
| 234 TextureLayer::CreateForMailbox(&client); |
102 ASSERT_TRUE(test_layer.get()); | 235 ASSERT_TRUE(test_layer.get()); |
103 scoped_ptr<TextureLayerImpl> impl_layer; | 236 test_layer->SetIsDrawable(true); |
104 impl_layer = TextureLayerImpl::Create(host_impl_.active_tree(), 1, false); | 237 test_layer->SetBounds(gfx::Size(10, 10)); |
105 ASSERT_TRUE(impl_layer); | 238 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
106 | |
107 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber()); | |
108 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); | 239 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
109 layer_tree_host_->SetRootLayer(test_layer); | 240 layer_tree_host_->SetRootLayer(test_layer); |
110 test_layer->SetTextureId(1); | |
111 test_layer->SetIsDrawable(true); | |
112 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 241 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
113 EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get()); | 242 EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get()); |
114 | 243 |
115 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(1); | 244 // Clearing the mailbox before we gave one should not sync. |
116 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); | 245 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
117 test_layer->WillModifyTexture(); | 246 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
| 247 test_layer->ClearTexture(); |
118 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 248 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
119 | 249 |
| 250 // Give a mailbox to the layer through the client. |
120 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); | 251 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
121 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); | 252 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
122 test_layer->SetNeedsDisplayRect(dirty_rect); | 253 client.set_mailbox(mailboxes.mailbox1_); |
| 254 test_layer->SetNeedsDisplay(); |
| 255 // Force a commit. |
| 256 layer_tree_host_->Composite(base::TimeTicks()); |
123 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 257 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
124 | 258 |
125 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); | 259 // Clearing the mailbox should sync. |
126 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1); | 260 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AtLeast(1)); |
127 test_layer->PushPropertiesTo(impl_layer.get()); // fake commit | 261 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
128 test_layer->SetIsDrawable(false); | 262 test_layer->ClearTexture(); |
129 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 263 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
130 | 264 |
131 // Verify that non-drawable layers don't signal the compositor, | 265 // But only once. |
132 // except for the first draw after last commit, which must acquire | 266 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
133 // the texture. | 267 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
134 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(1); | 268 test_layer->ClearTexture(); |
135 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); | |
136 test_layer->WillModifyTexture(); | |
137 test_layer->SetNeedsDisplayRect(dirty_rect); | |
138 test_layer->PushPropertiesTo(impl_layer.get()); // fake commit | |
139 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 269 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
140 | 270 |
141 // Second draw with layer in non-drawable state: no texture | 271 // Force a commit to give another mailbox. |
142 // acquisition. | |
143 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); | 272 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
144 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); | 273 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
145 test_layer->WillModifyTexture(); | 274 client.set_mailbox(mailboxes.mailbox2_); |
146 test_layer->SetNeedsDisplayRect(dirty_rect); | 275 test_layer->SetNeedsDisplay(); |
| 276 // Commit will return mailbox1. |
| 277 layer_tree_host_->Composite(base::TimeTicks()); |
147 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 278 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 279 |
| 280 // Wait for mailbox callback. |
| 281 { |
| 282 base::RunLoop run_loop; |
| 283 EXPECT_CALL(mailboxes.mock_callback_, |
| 284 Release(mailboxes.mailbox_name1_, _, false)) |
| 285 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
| 286 run_loop.Run(); |
| 287 } |
| 288 |
| 289 // Make undrawable and commit. |
| 290 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
| 291 test_layer->SetIsDrawable(false); |
| 292 layer_tree_host_->Composite(base::TimeTicks()); |
| 293 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 294 |
| 295 // Clearing textures should not sync. |
| 296 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
| 297 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
| 298 test_layer->ClearTexture(); |
| 299 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 300 |
| 301 // Commit will return the mailbox. |
| 302 layer_tree_host_->Composite(base::TimeTicks()); |
| 303 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 304 |
| 305 // Wait for mailbox callback. |
| 306 { |
| 307 base::RunLoop run_loop; |
| 308 EXPECT_CALL(mailboxes.mock_callback_, |
| 309 Release(mailboxes.mailbox_name2_, _, false)) |
| 310 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
| 311 run_loop.Run(); |
| 312 } |
148 } | 313 } |
149 | 314 |
150 TEST_F(TextureLayerTest, SyncImplWhenRemovingFromTree) { | 315 TEST_F(TextureLayerTest, SyncImplWhenRemovingFromTree) { |
151 scoped_refptr<Layer> root_layer = Layer::Create(); | 316 scoped_refptr<Layer> root_layer = Layer::Create(); |
152 ASSERT_TRUE(root_layer.get()); | 317 ASSERT_TRUE(root_layer.get()); |
153 scoped_refptr<Layer> child_layer = Layer::Create(); | 318 scoped_refptr<Layer> child_layer = Layer::Create(); |
154 ASSERT_TRUE(child_layer.get()); | 319 ASSERT_TRUE(child_layer.get()); |
155 root_layer->AddChild(child_layer); | 320 root_layer->AddChild(child_layer); |
156 scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(NULL); | 321 FakeTextureLayerClient client; |
| 322 scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(&client); |
| 323 test_layer->SetIsDrawable(true); |
| 324 test_layer->SetBounds(gfx::Size(10, 10)); |
157 ASSERT_TRUE(test_layer.get()); | 325 ASSERT_TRUE(test_layer.get()); |
158 test_layer->SetTextureId(0); | |
159 child_layer->AddChild(test_layer); | 326 child_layer->AddChild(test_layer); |
160 | 327 |
161 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber()); | 328 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber()); |
162 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); | 329 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
163 layer_tree_host_->SetRootLayer(root_layer); | 330 layer_tree_host_->SetRootLayer(root_layer); |
164 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 331 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
165 | 332 |
166 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); | 333 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
167 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | 334 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
168 test_layer->RemoveFromParent(); | 335 test_layer->RemoveFromParent(); |
169 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 336 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
170 | 337 |
171 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); | 338 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
172 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | 339 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
173 child_layer->AddChild(test_layer); | 340 child_layer->AddChild(test_layer); |
174 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 341 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
175 | 342 |
| 343 // Give a texture to the layer through the client. |
176 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); | 344 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); |
177 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | 345 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
178 test_layer->SetTextureId(1); | 346 client.set_texture(client.Context3d()->createTexture()); |
| 347 test_layer->SetNeedsDisplay(); |
| 348 // Force a commit. |
| 349 layer_tree_host_->Composite(base::TimeTicks()); |
179 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 350 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
180 | 351 |
181 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AtLeast(1)); | 352 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AtLeast(1)); |
182 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | 353 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
183 test_layer->RemoveFromParent(); | 354 test_layer->RemoveFromParent(); |
184 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 355 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
185 } | 356 } |
186 | 357 |
187 TEST_F(TextureLayerTest, CheckPropertyChangeCausesCorrectBehavior) { | 358 TEST_F(TextureLayerTest, CheckPropertyChangeCausesCorrectBehavior) { |
188 scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(NULL); | 359 scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(NULL); |
189 layer_tree_host_->SetRootLayer(test_layer); | 360 EXPECT_SET_NEEDS_COMMIT(1, layer_tree_host_->SetRootLayer(test_layer)); |
190 | 361 |
191 // Test properties that should call SetNeedsCommit. All properties need to | 362 // Test properties that should call SetNeedsCommit. All properties need to |
192 // be set to new values in order for SetNeedsCommit to be called. | 363 // be set to new values in order for SetNeedsCommit to be called. |
193 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetFlipped(false)); | 364 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetFlipped(false)); |
194 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetUV( | 365 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetUV( |
195 gfx::PointF(0.25f, 0.25f), gfx::PointF(0.75f, 0.75f))); | 366 gfx::PointF(0.25f, 0.25f), gfx::PointF(0.75f, 0.75f))); |
196 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetVertexOpacity( | 367 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetVertexOpacity( |
197 0.5f, 0.5f, 0.5f, 0.5f)); | 368 0.5f, 0.5f, 0.5f, 0.5f)); |
198 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetPremultipliedAlpha(false)); | 369 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetPremultipliedAlpha(false)); |
199 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBlendBackgroundColor(true)); | 370 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBlendBackgroundColor(true)); |
200 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetTextureId(1)); | 371 EXPECT_SET_NEEDS_COMMIT(1, test_layer->ClearTexture()); |
201 | |
202 // Calling SetTextureId can call AcquireLayerTextures. | |
203 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber()); | |
204 } | 372 } |
205 | 373 |
206 class FakeTextureLayerClient : public TextureLayerClient { | |
207 public: | |
208 FakeTextureLayerClient() | |
209 : context_(TestWebGraphicsContext3D::CreateShared()) {} | |
210 | |
211 virtual unsigned PrepareTexture() OVERRIDE { | |
212 return 0; | |
213 } | |
214 | |
215 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { | |
216 return context_.get(); | |
217 } | |
218 | |
219 virtual bool PrepareTextureMailbox(TextureMailbox* mailbox, | |
220 bool use_shared_memory) OVERRIDE { | |
221 *mailbox = TextureMailbox(); | |
222 return true; | |
223 } | |
224 | |
225 private: | |
226 scoped_ptr<TestWebGraphicsContext3D> context_; | |
227 DISALLOW_COPY_AND_ASSIGN(FakeTextureLayerClient); | |
228 }; | |
229 | |
230 TEST_F(TextureLayerTest, RateLimiter) { | 374 TEST_F(TextureLayerTest, RateLimiter) { |
231 FakeTextureLayerClient client; | 375 FakeTextureLayerClient client; |
232 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox( | 376 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox( |
233 &client); | 377 &client); |
234 test_layer->SetIsDrawable(true); | 378 test_layer->SetIsDrawable(true); |
235 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); | 379 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); |
236 layer_tree_host_->SetRootLayer(test_layer); | 380 layer_tree_host_->SetRootLayer(test_layer); |
237 | 381 |
238 // Don't rate limit until we invalidate. | 382 // Don't rate limit until we invalidate. |
239 EXPECT_CALL(*layer_tree_host_, StartRateLimiter(_)).Times(0); | 383 EXPECT_CALL(*layer_tree_host_, StartRateLimiter(_)).Times(0); |
(...skipping 29 matching lines...) Expand all Loading... |
269 EXPECT_CALL(*layer_tree_host_, StartRateLimiter(client.Context3d())); | 413 EXPECT_CALL(*layer_tree_host_, StartRateLimiter(client.Context3d())); |
270 test_layer->SetNeedsDisplay(); | 414 test_layer->SetNeedsDisplay(); |
271 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 415 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
272 | 416 |
273 // Stop rate limiter when we're removed from the tree. | 417 // Stop rate limiter when we're removed from the tree. |
274 EXPECT_CALL(*layer_tree_host_, StopRateLimiter(client.Context3d())); | 418 EXPECT_CALL(*layer_tree_host_, StopRateLimiter(client.Context3d())); |
275 layer_tree_host_->SetRootLayer(NULL); | 419 layer_tree_host_->SetRootLayer(NULL); |
276 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 420 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
277 } | 421 } |
278 | 422 |
279 class MockMailboxCallback { | |
280 public: | |
281 MOCK_METHOD3(Release, void(const std::string& mailbox, | |
282 unsigned sync_point, | |
283 bool lost_resource)); | |
284 MOCK_METHOD3(Release2, void(base::SharedMemory* shared_memory, | |
285 unsigned sync_point, | |
286 bool lost_resource)); | |
287 }; | |
288 | |
289 struct CommonMailboxObjects { | |
290 CommonMailboxObjects() | |
291 : mailbox_name1_(64, '1'), | |
292 mailbox_name2_(64, '2'), | |
293 sync_point1_(1), | |
294 sync_point2_(2), | |
295 shared_memory_(new base::SharedMemory) { | |
296 release_mailbox1_ = base::Bind(&MockMailboxCallback::Release, | |
297 base::Unretained(&mock_callback_), | |
298 mailbox_name1_); | |
299 release_mailbox2_ = base::Bind(&MockMailboxCallback::Release, | |
300 base::Unretained(&mock_callback_), | |
301 mailbox_name2_); | |
302 gpu::Mailbox m1; | |
303 m1.SetName(reinterpret_cast<const int8*>(mailbox_name1_.data())); | |
304 mailbox1_ = TextureMailbox(m1, release_mailbox1_, sync_point1_); | |
305 gpu::Mailbox m2; | |
306 m2.SetName(reinterpret_cast<const int8*>(mailbox_name2_.data())); | |
307 mailbox2_ = TextureMailbox(m2, release_mailbox2_, sync_point2_); | |
308 | |
309 gfx::Size size(128, 128); | |
310 EXPECT_TRUE(shared_memory_->CreateAndMapAnonymous(4 * size.GetArea())); | |
311 release_mailbox3_ = base::Bind(&MockMailboxCallback::Release2, | |
312 base::Unretained(&mock_callback_), | |
313 shared_memory_.get()); | |
314 mailbox3_ = TextureMailbox(shared_memory_.get(), size, release_mailbox3_); | |
315 } | |
316 | |
317 std::string mailbox_name1_; | |
318 std::string mailbox_name2_; | |
319 MockMailboxCallback mock_callback_; | |
320 TextureMailbox::ReleaseCallback release_mailbox1_; | |
321 TextureMailbox::ReleaseCallback release_mailbox2_; | |
322 TextureMailbox::ReleaseCallback release_mailbox3_; | |
323 TextureMailbox mailbox1_; | |
324 TextureMailbox mailbox2_; | |
325 TextureMailbox mailbox3_; | |
326 unsigned sync_point1_; | |
327 unsigned sync_point2_; | |
328 scoped_ptr<base::SharedMemory> shared_memory_; | |
329 }; | |
330 | |
331 class TextureLayerWithMailboxTest : public TextureLayerTest { | 423 class TextureLayerWithMailboxTest : public TextureLayerTest { |
332 protected: | 424 protected: |
333 virtual void TearDown() { | 425 virtual void TearDown() { |
334 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 426 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
335 EXPECT_CALL(test_data_.mock_callback_, | 427 EXPECT_CALL(test_data_.mock_callback_, |
336 Release(test_data_.mailbox_name1_, | 428 Release(test_data_.mailbox_name1_, |
337 test_data_.sync_point1_, | 429 test_data_.sync_point1_, |
338 false)).Times(1); | 430 false)).Times(1); |
339 TextureLayerTest::TearDown(); | 431 TextureLayerTest::TearDown(); |
340 } | 432 } |
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
944 scoped_refptr<TextureLayer> texture_layer_; | 1036 scoped_refptr<TextureLayer> texture_layer_; |
945 scoped_ptr<TestWebGraphicsContext3D> texture_context_; | 1037 scoped_ptr<TestWebGraphicsContext3D> texture_context_; |
946 unsigned texture_; | 1038 unsigned texture_; |
947 int draw_count_; | 1039 int draw_count_; |
948 }; | 1040 }; |
949 | 1041 |
950 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(TextureLayerLostContextTest); | 1042 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(TextureLayerLostContextTest); |
951 | 1043 |
952 } // namespace | 1044 } // namespace |
953 } // namespace cc | 1045 } // namespace cc |
OLD | NEW |