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

Side by Side Diff: cc/texture_layer_unittest.cc

Issue 11638028: Mailbox support for texture layers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments Created 7 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/texture_layer_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/texture_layer.h" 5 #include "cc/texture_layer.h"
6 6
7 #include <string>
8
9 #include "base/callback.h"
7 #include "cc/layer_tree_host.h" 10 #include "cc/layer_tree_host.h"
11 #include "cc/layer_tree_impl.h"
8 #include "cc/single_thread_proxy.h" 12 #include "cc/single_thread_proxy.h"
9 #include "cc/test/fake_impl_proxy.h" 13 #include "cc/test/fake_impl_proxy.h"
10 #include "cc/test/fake_layer_tree_host_client.h" 14 #include "cc/test/fake_layer_tree_host_client.h"
11 #include "cc/test/fake_layer_tree_host_impl.h" 15 #include "cc/test/fake_layer_tree_host_impl.h"
16 #include "cc/test/layer_tree_test_common.h"
12 #include "cc/texture_layer_impl.h" 17 #include "cc/texture_layer_impl.h"
13 #include "cc/thread.h" 18 #include "cc/thread.h"
14 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
16 21
17 using ::testing::Mock; 22 using ::testing::Mock;
18 using ::testing::_; 23 using ::testing::_;
19 using ::testing::AtLeast; 24 using ::testing::AtLeast;
20 using ::testing::AnyNumber; 25 using ::testing::AnyNumber;
21 26
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); 98 Mock::VerifyAndClearExpectations(m_layerTreeHost.get());
94 } 99 }
95 100
96 TEST_F(TextureLayerTest, syncImplWhenDrawing) 101 TEST_F(TextureLayerTest, syncImplWhenDrawing)
97 { 102 {
98 gfx::RectF dirtyRect(0, 0, 1, 1); 103 gfx::RectF dirtyRect(0, 0, 1, 1);
99 104
100 scoped_refptr<TextureLayer> testLayer = TextureLayer::create(0); 105 scoped_refptr<TextureLayer> testLayer = TextureLayer::create(0);
101 ASSERT_TRUE(testLayer); 106 ASSERT_TRUE(testLayer);
102 scoped_ptr<TextureLayerImpl> implLayer; 107 scoped_ptr<TextureLayerImpl> implLayer;
103 implLayer = TextureLayerImpl::create(m_hostImpl.activeTree(), 1); 108 implLayer = TextureLayerImpl::create(m_hostImpl.activeTree(), 1, false);
104 ASSERT_TRUE(implLayer); 109 ASSERT_TRUE(implLayer);
105 110
106 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AnyNumber()); 111 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AnyNumber());
107 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AnyNumber()); 112 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AnyNumber());
108 m_layerTreeHost->setRootLayer(testLayer); 113 m_layerTreeHost->setRootLayer(testLayer);
109 testLayer->setTextureId(1); 114 testLayer->setTextureId(1);
110 testLayer->setIsDrawable(true); 115 testLayer->setIsDrawable(true);
111 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); 116 Mock::VerifyAndClearExpectations(m_layerTreeHost.get());
112 EXPECT_EQ(testLayer->layerTreeHost(), m_layerTreeHost.get()); 117 EXPECT_EQ(testLayer->layerTreeHost(), m_layerTreeHost.get());
113 118
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1)); 182 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1));
178 testLayer->setTextureId(1); 183 testLayer->setTextureId(1);
179 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); 184 Mock::VerifyAndClearExpectations(m_layerTreeHost.get());
180 185
181 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AtLeast(1)); 186 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AtLeast(1));
182 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1)); 187 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1));
183 testLayer->removeFromParent(); 188 testLayer->removeFromParent();
184 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); 189 Mock::VerifyAndClearExpectations(m_layerTreeHost.get());
185 } 190 }
186 191
192 class MockMailboxCallback {
193 public:
194 MOCK_METHOD2(Release, void(const std::string& mailbox, unsigned syncPoint));
195 };
196
197 struct CommonMailboxObjects {
198 CommonMailboxObjects()
199 : m_mailbox1(64, '1')
200 , m_mailbox2(64, '2')
201 {
202 m_releaseMailbox1 = base::Bind(&MockMailboxCallback::Release,
203 base::Unretained(&m_mockCallback),
204 m_mailbox1);
205 m_releaseMailbox2 = base::Bind(&MockMailboxCallback::Release,
206 base::Unretained(&m_mockCallback),
207 m_mailbox2);
208 }
209
210 std::string m_mailbox1;
211 std::string m_mailbox2;
212 MockMailboxCallback m_mockCallback;
213 TextureLayer::MailboxCallback m_releaseMailbox1;
214 TextureLayer::MailboxCallback m_releaseMailbox2;
215 };
216
217 class TextureLayerWithMailboxTest : public TextureLayerTest {
218 protected:
219 virtual void TearDown()
220 {
221 Mock::VerifyAndClearExpectations(&m_testData.m_mockCallback);
222 EXPECT_CALL(m_testData.m_mockCallback,
223 Release(m_testData.m_mailbox1, _)).Times(1);
224 TextureLayerTest::TearDown();
225 }
226
227 CommonMailboxObjects m_testData;
228 };
229
230 TEST_F(TextureLayerWithMailboxTest, replaceMailboxOnMainThreadBeforeCommit)
231 {
232 scoped_refptr<TextureLayer> testLayer = TextureLayer::createForMailbox();
233 ASSERT_TRUE(testLayer);
234
235 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0);
236 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AnyNumber());
237 m_layerTreeHost->setRootLayer(testLayer);
238 Mock::VerifyAndClearExpectations(m_layerTreeHost.get());
239
240 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0);
241 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1));
242 testLayer->setTextureMailbox(m_testData.m_mailbox1,
243 m_testData.m_releaseMailbox1);
244 Mock::VerifyAndClearExpectations(m_layerTreeHost.get());
245
246 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0);
247 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1));
248 EXPECT_CALL(m_testData.m_mockCallback,
249 Release(m_testData.m_mailbox1, _)).Times(1);
250 testLayer->setTextureMailbox(m_testData.m_mailbox2,
251 m_testData.m_releaseMailbox2);
252 Mock::VerifyAndClearExpectations(m_layerTreeHost.get());
253 Mock::VerifyAndClearExpectations(&m_testData.m_mockCallback);
254
255 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0);
256 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1));
257 EXPECT_CALL(m_testData.m_mockCallback,
258 Release(m_testData.m_mailbox2, _)).Times(1);
259 testLayer->setTextureMailbox(std::string(),
260 TextureLayer::MailboxCallback());
261 Mock::VerifyAndClearExpectations(m_layerTreeHost.get());
262 Mock::VerifyAndClearExpectations(&m_testData.m_mockCallback);
263
264 // Test destructor.
265 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1));
266 testLayer->setTextureMailbox(m_testData.m_mailbox1,
267 m_testData.m_releaseMailbox1);
268 }
269
270 class TextureLayerImplWithMailboxThreadedCallback : public ThreadedTest {
271 public:
272 TextureLayerImplWithMailboxThreadedCallback()
273 : m_resetMailbox(false)
274 {
275 }
276
277 // Make sure callback is received on main and doesn't block the impl thread.
278 void releaseCallback(unsigned syncPoint) {
279 EXPECT_EQ(true, proxy()->isMainThread());
280 endTest();
281 }
282
283 virtual void beginTest() OVERRIDE
284 {
285 m_layer = TextureLayer::createForMailbox();
286 m_layer->setIsDrawable(true);
287 m_layerTreeHost->setRootLayer(m_layer);
288 m_layer->setTextureMailbox(
289 std::string(64, '1'),
290 base::Bind(
291 &TextureLayerImplWithMailboxThreadedCallback::releaseCallback,
292 base::Unretained(this)));
293 postSetNeedsCommitToMainThread();
294 }
295
296 virtual void didCommit() OVERRIDE
297 {
298 if (m_resetMailbox)
299 return;
300
301 m_layer->setTextureMailbox(std::string(),
302 TextureLayer::MailboxCallback());
303 m_resetMailbox = true;
304 }
305
306 virtual void afterTest() OVERRIDE
307 {
308 }
309
310 private:
311 bool m_resetMailbox;
312 scoped_refptr<TextureLayer> m_layer;
313 };
314
315 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerImplWithMailboxThreadedCallback);
316
317 class TextureLayerImplWithMailboxTest : public TextureLayerTest {
318 protected:
319 virtual void SetUp()
320 {
321 TextureLayerTest::SetUp();
322 m_layerTreeHost.reset(new MockLayerImplTreeHost);
323 EXPECT_TRUE(m_hostImpl.initializeRenderer(createFakeOutputSurface()));
324 }
325
326 CommonMailboxObjects m_testData;
327 };
328
329 TEST_F(TextureLayerImplWithMailboxTest, testImplLayerCallbacks)
330 {
331 scoped_ptr<TextureLayerImpl> implLayer;
332 implLayer = TextureLayerImpl::create(m_hostImpl.activeTree(), 1, true);
333 ASSERT_TRUE(implLayer);
334
335 // Test setting identical mailbox.
336 EXPECT_CALL(m_testData.m_mockCallback, Release(_, _)).Times(0);
337 implLayer->setTextureMailbox(m_testData.m_mailbox1,
338 m_testData.m_releaseMailbox1);
339 implLayer->setTextureMailbox(m_testData.m_mailbox1,
340 m_testData.m_releaseMailbox1);
341 Mock::VerifyAndClearExpectations(&m_testData.m_mockCallback);
342
343 // Test multiple commits without a draw.
344 EXPECT_CALL(m_testData.m_mockCallback,
345 Release(m_testData.m_mailbox1, _)).Times(1);
346 implLayer->setTextureMailbox(m_testData.m_mailbox2,
347 m_testData.m_releaseMailbox2);
348 Mock::VerifyAndClearExpectations(&m_testData.m_mockCallback);
349
350 // Test resetting the mailbox.
351 EXPECT_CALL(m_testData.m_mockCallback,
352 Release(m_testData.m_mailbox2, _)).Times(1);
353 implLayer->setTextureMailbox(std::string(),
354 TextureLayer::MailboxCallback());
355 Mock::VerifyAndClearExpectations(&m_testData.m_mockCallback);
356
357 // Test destructor.
358 EXPECT_CALL(m_testData.m_mockCallback,
359 Release(m_testData.m_mailbox1, _)).Times(1);
360 implLayer->setTextureMailbox(m_testData.m_mailbox1,
361 m_testData.m_releaseMailbox1);
362 }
363
364 TEST_F(TextureLayerImplWithMailboxTest, testDestructorCallbackOnCreatedResource)
365 {
366 scoped_ptr<TextureLayerImpl> implLayer;
367 implLayer = TextureLayerImpl::create(m_hostImpl.activeTree(), 1, true);
368 ASSERT_TRUE(implLayer);
369
370 EXPECT_CALL(m_testData.m_mockCallback,
371 Release(m_testData.m_mailbox1, _)).Times(1);
372 implLayer->setTextureMailbox(m_testData.m_mailbox1,
373 m_testData.m_releaseMailbox1);
374 implLayer->willDraw(m_hostImpl.activeTree()->resource_provider());
375 implLayer->didDraw(m_hostImpl.activeTree()->resource_provider());
376 implLayer->setTextureMailbox(std::string(),
377 TextureLayer::MailboxCallback());
378 }
379
380 TEST_F(TextureLayerImplWithMailboxTest, testCallbackOnInUseResource)
381 {
382 ResourceProvider *provider = m_hostImpl.activeTree()->resource_provider();
383 ResourceProvider::ResourceId id =
384 provider->createResourceFromTextureMailbox(
385 m_testData.m_mailbox1,
386 m_testData.m_releaseMailbox1);
387
388 // Transfer some resources to the parent.
389 ResourceProvider::ResourceIdArray resourceIdsToTransfer;
390 resourceIdsToTransfer.push_back(id);
391 TransferableResourceList list;
392 provider->prepareSendToParent(resourceIdsToTransfer, &list);
393 EXPECT_TRUE(provider->inUseByConsumer(id));
394 EXPECT_CALL(m_testData.m_mockCallback, Release(_, _)).Times(0);
395 provider->deleteResource(id);
396 Mock::VerifyAndClearExpectations(&m_testData.m_mockCallback);
397 EXPECT_CALL(m_testData.m_mockCallback,
398 Release(m_testData.m_mailbox1, _)).Times(1);
399 provider->receiveFromParent(list);
400 }
401
187 } // namespace 402 } // namespace
188 } // namespace cc 403 } // namespace cc
OLDNEW
« no previous file with comments | « cc/texture_layer_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698