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

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: Tests 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
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 <string>
danakj 2013/01/04 15:10:35 put this between cc/texture_layer.h and the rest o
6
7 #include "base/callback.h"
danakj 2013/01/04 15:10:35 move this header to the top of the next group of h
5 #include "cc/texture_layer.h" 8 #include "cc/texture_layer.h"
6 9
7 #include "cc/layer_tree_host.h" 10 #include "cc/layer_tree_host.h"
8 #include "cc/single_thread_proxy.h" 11 #include "cc/single_thread_proxy.h"
9 #include "cc/test/fake_impl_proxy.h" 12 #include "cc/test/fake_impl_proxy.h"
10 #include "cc/test/fake_layer_tree_host_client.h" 13 #include "cc/test/fake_layer_tree_host_client.h"
11 #include "cc/test/fake_layer_tree_host_impl.h" 14 #include "cc/test/fake_layer_tree_host_impl.h"
15 #include "cc/test/layer_tree_test_common.h"
12 #include "cc/texture_layer_impl.h" 16 #include "cc/texture_layer_impl.h"
13 #include "cc/thread.h" 17 #include "cc/thread.h"
14 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
16 20
17 using ::testing::Mock; 21 using ::testing::Mock;
18 using ::testing::_; 22 using ::testing::_;
19 using ::testing::AtLeast; 23 using ::testing::AtLeast;
20 using ::testing::AnyNumber; 24 using ::testing::AnyNumber;
21 25
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); 97 Mock::VerifyAndClearExpectations(m_layerTreeHost.get());
94 } 98 }
95 99
96 TEST_F(TextureLayerTest, syncImplWhenDrawing) 100 TEST_F(TextureLayerTest, syncImplWhenDrawing)
97 { 101 {
98 gfx::RectF dirtyRect(0, 0, 1, 1); 102 gfx::RectF dirtyRect(0, 0, 1, 1);
99 103
100 scoped_refptr<TextureLayer> testLayer = TextureLayer::create(0); 104 scoped_refptr<TextureLayer> testLayer = TextureLayer::create(0);
101 ASSERT_TRUE(testLayer); 105 ASSERT_TRUE(testLayer);
102 scoped_ptr<TextureLayerImpl> implLayer; 106 scoped_ptr<TextureLayerImpl> implLayer;
103 implLayer = TextureLayerImpl::create(m_hostImpl.activeTree(), 1); 107 implLayer = TextureLayerImpl::create(m_hostImpl.activeTree(), 1, false);
104 ASSERT_TRUE(implLayer); 108 ASSERT_TRUE(implLayer);
105 109
106 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AnyNumber()); 110 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AnyNumber());
107 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AnyNumber()); 111 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AnyNumber());
108 m_layerTreeHost->setRootLayer(testLayer); 112 m_layerTreeHost->setRootLayer(testLayer);
109 testLayer->setTextureId(1); 113 testLayer->setTextureId(1);
110 testLayer->setIsDrawable(true); 114 testLayer->setIsDrawable(true);
111 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); 115 Mock::VerifyAndClearExpectations(m_layerTreeHost.get());
112 EXPECT_EQ(testLayer->layerTreeHost(), m_layerTreeHost.get()); 116 EXPECT_EQ(testLayer->layerTreeHost(), m_layerTreeHost.get());
113 117
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1)); 181 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1));
178 testLayer->setTextureId(1); 182 testLayer->setTextureId(1);
179 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); 183 Mock::VerifyAndClearExpectations(m_layerTreeHost.get());
180 184
181 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AtLeast(1)); 185 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(AtLeast(1));
182 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1)); 186 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1));
183 testLayer->removeFromParent(); 187 testLayer->removeFromParent();
184 Mock::VerifyAndClearExpectations(m_layerTreeHost.get()); 188 Mock::VerifyAndClearExpectations(m_layerTreeHost.get());
185 } 189 }
186 190
191 class MockMailboxCallback {
192 public:
193 MOCK_METHOD2(Release, void(const std::string& mailbox, unsigned syncPoint));
194 };
195
196 struct CommonMailboxObjects {
197 CommonMailboxObjects()
198 : m_mailbox1(64, '1')
199 , m_mailbox2(64, '2')
200 {
201 m_releaseMailbox1 = base::Bind(&MockMailboxCallback::Release,
202 base::Unretained(&m_mockCallback),
203 m_mailbox1);
204 m_releaseMailbox2 = base::Bind(&MockMailboxCallback::Release,
205 base::Unretained(&m_mockCallback),
206 m_mailbox2);
207 }
208
209 std::string m_mailbox1;
210 std::string m_mailbox2;
211 MockMailboxCallback m_mockCallback;
212 base::Callback<void(unsigned)> m_releaseMailbox1;
213 base::Callback<void(unsigned)> m_releaseMailbox2;
214 };
215
216 TEST_F(TextureLayerTest, testImplLayerCallbacks)
217 {
218 CommonMailboxObjects m_testData;
219 {
danakj 2013/01/04 15:10:35 the extra scoping/indent here doesn't seem useful?
alexst (slow to review) 2013/01/04 16:20:48 It's to ensure the object receiving callbacks outl
danakj 2013/01/04 21:36:27 I see. Can you add a quick comment here to that ef
220 scoped_ptr<TextureLayerImpl> implLayer;
221 implLayer = TextureLayerImpl::create(m_hostImpl.activeTree(), 1, true);
222 ASSERT_TRUE(implLayer);
223
224 // Test setting identical mailbox.
225 EXPECT_CALL(m_testData.m_mockCallback, Release(_, _)).Times(0);
226 implLayer->setTextureMailbox(m_testData.m_mailbox1,
227 m_testData.m_releaseMailbox1);
228 implLayer->setTextureMailbox(m_testData.m_mailbox1,
229 m_testData.m_releaseMailbox1);
230 Mock::VerifyAndClearExpectations(&m_testData.m_mockCallback);
231
232 // Test multiple commits without a draw.
233 EXPECT_CALL(m_testData.m_mockCallback,
234 Release(m_testData.m_mailbox1, _)).Times(1);
235 implLayer->setTextureMailbox(m_testData.m_mailbox2,
236 m_testData.m_releaseMailbox2);
237 Mock::VerifyAndClearExpectations(&m_testData.m_mockCallback);
238
239 // Test resetting the mailbox.
danakj 2013/01/04 15:10:35 How about the case when the resource from the mail
danakj 2013/01/04 21:36:27 Do you think this is something we can test here? M
240 EXPECT_CALL(m_testData.m_mockCallback,
241 Release(m_testData.m_mailbox2, _)).Times(1);
242 implLayer->setTextureMailbox(std::string(),
243 base::Callback<void(unsigned)>());
244 Mock::VerifyAndClearExpectations(&m_testData.m_mockCallback);
245
246 // Test destructor.
247 EXPECT_CALL(m_testData.m_mockCallback,
248 Release(m_testData.m_mailbox1, _)).Times(1);
danakj 2013/01/04 15:10:35 Since you just cleared it, how will this happen?
alexst (slow to review) 2013/01/04 16:20:48 This next expectation is for mailbox1 set below, t
249 implLayer->setTextureMailbox(m_testData.m_mailbox1,
250 m_testData.m_releaseMailbox1);
251 }
252 }
253
254 class TextureLayerWithMailboxTest : public TextureLayerTest {
255 protected:
256 virtual void TearDown()
257 {
258 Mock::VerifyAndClearExpectations(&m_testData.m_mockCallback);
259 EXPECT_CALL(m_testData.m_mockCallback,
260 Release(m_testData.m_mailbox1, _)).Times(1);
261 TextureLayerTest::TearDown();
262 }
263
264 CommonMailboxObjects m_testData;
265 };
266
267 TEST_F(TextureLayerWithMailboxTest, syncImplAndGetCallback)
danakj 2013/01/04 15:10:35 I think this test name is wrong, it is not doing a
alexst (slow to review) 2013/01/04 16:20:48 Done.
268 {
269 scoped_refptr<TextureLayer> testLayer = TextureLayer::createForMailbox();
270 ASSERT_TRUE(testLayer);
271
272 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0);
273 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AnyNumber());
274 m_layerTreeHost->setRootLayer(testLayer);
275 Mock::VerifyAndClearExpectations(m_layerTreeHost.get());
276
277 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0);
278 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1));
279 EXPECT_CALL(m_testData.m_mockCallback,
280 Release(m_testData.m_mailbox1, _)).Times(1);
danakj 2013/01/04 15:10:35 Seems like this EXPECT should move to line 287?
alexst (slow to review) 2013/01/04 16:20:48 Done.
281 testLayer->setTextureMailbox(m_testData.m_mailbox1,
282 m_testData.m_releaseMailbox1);
283 Mock::VerifyAndClearExpectations(m_layerTreeHost.get());
284
285 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0);
286 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1));
287
288 testLayer->setTextureMailbox(m_testData.m_mailbox2,
289 m_testData.m_releaseMailbox2);
290 Mock::VerifyAndClearExpectations(m_layerTreeHost.get());
291 Mock::VerifyAndClearExpectations(&m_testData.m_mockCallback);
292
293 EXPECT_CALL(*m_layerTreeHost, acquireLayerTextures()).Times(0);
294 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1));
295 EXPECT_CALL(m_testData.m_mockCallback,
296 Release(m_testData.m_mailbox2, _)).Times(1);
297 testLayer->setTextureMailbox(std::string(),
298 base::Callback<void(unsigned)>());
299 Mock::VerifyAndClearExpectations(m_layerTreeHost.get());
300 Mock::VerifyAndClearExpectations(&m_testData.m_mockCallback);
301
302 // Test destructor.
303 EXPECT_CALL(*m_layerTreeHost, setNeedsCommit()).Times(AtLeast(1));
304 testLayer->setTextureMailbox(m_testData.m_mailbox1,
305 m_testData.m_releaseMailbox1);
306 }
307
308 class TextureLayerImplWithMailbox : public ThreadedTest {
309 public:
310 TextureLayerImplWithMailbox()
311 : m_resetMailbox(false)
312 {
313 }
314
315 // Make sure callback is received on main and doesn't block the impl thread.
316 void releaseCallback(unsigned syncPoint) {
317 EXPECT_EQ(proxy()->isMainThread(), true);
danakj 2013/01/04 15:10:35 nit: (expected value, actual value) Otherwise the
318 endTest();
319 }
320
321 virtual void beginTest() OVERRIDE
322 {
323 m_layerTreeHost->initializeRendererIfNeeded();
danakj 2013/01/04 15:10:35 I don't think you should need this line?
alexst (slow to review) 2013/01/04 16:20:48 Done.
324
325 m_layer = TextureLayer::createForMailbox();
326 m_layer->setIsDrawable(true);
327 m_layerTreeHost->setRootLayer(m_layer);
328 m_layer->setTextureMailbox(
329 std::string(64, '1'),
330 base::Bind(&TextureLayerImplWithMailbox::releaseCallback,
331 base::Unretained(this)));
332 postSetNeedsCommitToMainThread();
333 }
334
335 virtual void didCommit() OVERRIDE {
danakj 2013/01/04 15:10:35 nit: { on new line
alexst (slow to review) 2013/01/04 16:20:48 Done.
336 if (m_resetMailbox)
337 return;
338
339 m_layer->setTextureMailbox(std::string(),
340 base::Callback<void(unsigned)>());
341 m_resetMailbox = true;
342 }
343
344 virtual void afterTest() OVERRIDE {
danakj 2013/01/04 15:10:35 nit: { on new line
alexst (slow to review) 2013/01/04 16:20:48 Done.
345 }
346
347 private:
348 bool m_resetMailbox;
349 scoped_refptr<TextureLayer> m_layer;
350 };
351
352 MULTI_THREAD_TEST_F(TextureLayerImplWithMailbox);
danakj 2013/01/04 15:10:35 would this work as SINGLE_AND_MULTI_THREAD_TEST_F?
alexst (slow to review) 2013/01/04 16:20:48 Done.
353
187 } // namespace 354 } // namespace
188 } // namespace cc 355 } // namespace cc
OLDNEW
« cc/texture_layer.h ('K') | « cc/texture_layer_impl.cc ('k') | cc/transferable_resource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698