blob: 6bc66984b3a90514b18045291f39ba73ae3f1e7c [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]de44a152013-01-08 15:28:467#include <string>
8
9#include "base/callback.h"
[email protected]681ccff2013-03-18 06:13:5210#include "cc/base/thread.h"
[email protected]d50c6862012-10-23 02:08:3111#include "cc/layer_tree_host.h"
[email protected]de44a152013-01-08 15:28:4612#include "cc/layer_tree_impl.h"
[email protected]031ccfff2012-10-26 00:57:3813#include "cc/single_thread_proxy.h"
[email protected]586d51ed2012-12-07 20:31:4514#include "cc/test/fake_impl_proxy.h"
[email protected]101441ce2012-10-16 01:45:0315#include "cc/test/fake_layer_tree_host_client.h"
[email protected]586d51ed2012-12-07 20:31:4516#include "cc/test/fake_layer_tree_host_impl.h"
[email protected]de44a152013-01-08 15:28:4617#include "cc/test/layer_tree_test_common.h"
[email protected]586d51ed2012-12-07 20:31:4518#include "cc/texture_layer_impl.h"
[email protected]7f0c53db2012-10-02 00:23:1819#include "testing/gmock/include/gmock/gmock.h"
20#include "testing/gtest/include/gtest/gtest.h"
[email protected]c0dd24c2012-08-30 23:25:2721
[email protected]c0dd24c2012-08-30 23:25:2722using ::testing::Mock;
23using ::testing::_;
24using ::testing::AtLeast;
25using ::testing::AnyNumber;
26
[email protected]ba565742012-11-10 09:29:4827namespace cc {
[email protected]c0dd24c2012-08-30 23:25:2728namespace {
29
[email protected]96baf3e2012-10-22 23:09:5530class MockLayerImplTreeHost : public LayerTreeHost {
[email protected]28571b042013-03-14 07:59:1531 public:
32 MockLayerImplTreeHost() : LayerTreeHost(&fake_client_, LayerTreeSettings()) {
33 Initialize(scoped_ptr<Thread>(NULL));
34 }
[email protected]c0dd24c2012-08-30 23:25:2735
[email protected]28571b042013-03-14 07:59:1536 MOCK_METHOD0(AcquireLayerTextures, void());
37 MOCK_METHOD0(SetNeedsCommit, void());
[email protected]c0dd24c2012-08-30 23:25:2738
[email protected]28571b042013-03-14 07:59:1539 private:
40 FakeLayerImplTreeHostClient fake_client_;
[email protected]c0dd24c2012-08-30 23:25:2741};
42
[email protected]96baf3e2012-10-22 23:09:5543class TextureLayerTest : public testing::Test {
[email protected]28571b042013-03-14 07:59:1544 public:
45 TextureLayerTest() : host_impl_(&proxy_) {}
[email protected]0f077a52012-09-08 01:45:2446
[email protected]28571b042013-03-14 07:59:1547 protected:
48 virtual void SetUp() {
49 layer_tree_host_.reset(new MockLayerImplTreeHost);
50 }
[email protected]c0dd24c2012-08-30 23:25:2751
[email protected]28571b042013-03-14 07:59:1552 virtual void TearDown() {
53 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
54 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber());
55 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
[email protected]c0dd24c2012-08-30 23:25:2756
[email protected]28571b042013-03-14 07:59:1557 layer_tree_host_->SetRootLayer(NULL);
58 layer_tree_host_.reset();
59 }
[email protected]c0dd24c2012-08-30 23:25:2760
[email protected]28571b042013-03-14 07:59:1561 scoped_ptr<MockLayerImplTreeHost> layer_tree_host_;
62 FakeImplProxy proxy_;
63 FakeLayerTreeHostImpl host_impl_;
[email protected]c0dd24c2012-08-30 23:25:2764};
65
[email protected]28571b042013-03-14 07:59:1566TEST_F(TextureLayerTest, SyncImplWhenChangingTextureId) {
67 scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(NULL);
68 ASSERT_TRUE(test_layer);
[email protected]c0dd24c2012-08-30 23:25:2769
[email protected]28571b042013-03-14 07:59:1570 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber());
71 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
72 layer_tree_host_->SetRootLayer(test_layer);
73 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
74 EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get());
[email protected]c0dd24c2012-08-30 23:25:2775
[email protected]28571b042013-03-14 07:59:1576 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
77 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
78 test_layer->SetTextureId(1);
79 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]c0dd24c2012-08-30 23:25:2780
[email protected]28571b042013-03-14 07:59:1581 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AtLeast(1));
82 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
83 test_layer->SetTextureId(2);
84 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]c0dd24c2012-08-30 23:25:2785
[email protected]28571b042013-03-14 07:59:1586 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AtLeast(1));
87 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
88 test_layer->SetTextureId(0);
89 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]c0dd24c2012-08-30 23:25:2790}
91
[email protected]28571b042013-03-14 07:59:1592TEST_F(TextureLayerTest, SyncImplWhenDrawing) {
93 gfx::RectF dirty_rect(0.f, 0.f, 1.f, 1.f);
[email protected]031ccfff2012-10-26 00:57:3894
[email protected]28571b042013-03-14 07:59:1595 scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(NULL);
96 ASSERT_TRUE(test_layer);
97 scoped_ptr<TextureLayerImpl> impl_layer;
98 impl_layer = TextureLayerImpl::Create(host_impl_.active_tree(), 1, false);
99 ASSERT_TRUE(impl_layer);
[email protected]031ccfff2012-10-26 00:57:38100
[email protected]28571b042013-03-14 07:59:15101 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber());
102 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
103 layer_tree_host_->SetRootLayer(test_layer);
104 test_layer->SetTextureId(1);
105 test_layer->SetIsDrawable(true);
106 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
107 EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get());
[email protected]031ccfff2012-10-26 00:57:38108
[email protected]28571b042013-03-14 07:59:15109 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(1);
110 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0);
111 test_layer->WillModifyTexture();
112 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]031ccfff2012-10-26 00:57:38113
[email protected]28571b042013-03-14 07:59:15114 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
115 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1);
116 test_layer->SetNeedsDisplayRect(dirty_rect);
117 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]031ccfff2012-10-26 00:57:38118
[email protected]28571b042013-03-14 07:59:15119 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
120 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1);
121 test_layer->PushPropertiesTo(impl_layer.get()); // fake commit
122 test_layer->SetIsDrawable(false);
123 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]031ccfff2012-10-26 00:57:38124
[email protected]28571b042013-03-14 07:59:15125 // Verify that non-drawable layers don't signal the compositor,
126 // except for the first draw after last commit, which must acquire
127 // the texture.
128 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(1);
129 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0);
130 test_layer->WillModifyTexture();
131 test_layer->SetNeedsDisplayRect(dirty_rect);
132 test_layer->PushPropertiesTo(impl_layer.get()); // fake commit
133 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]031ccfff2012-10-26 00:57:38134
[email protected]28571b042013-03-14 07:59:15135 // Second draw with layer in non-drawable state: no texture
136 // acquisition.
137 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
138 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0);
139 test_layer->WillModifyTexture();
140 test_layer->SetNeedsDisplayRect(dirty_rect);
141 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]031ccfff2012-10-26 00:57:38142}
143
[email protected]28571b042013-03-14 07:59:15144TEST_F(TextureLayerTest, SyncImplWhenRemovingFromTree) {
145 scoped_refptr<Layer> root_layer = Layer::Create();
146 ASSERT_TRUE(root_layer);
147 scoped_refptr<Layer> child_layer = Layer::Create();
148 ASSERT_TRUE(child_layer);
149 root_layer->AddChild(child_layer);
150 scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(NULL);
151 ASSERT_TRUE(test_layer);
152 test_layer->SetTextureId(0);
153 child_layer->AddChild(test_layer);
[email protected]c0dd24c2012-08-30 23:25:27154
[email protected]28571b042013-03-14 07:59:15155 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber());
156 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
157 layer_tree_host_->SetRootLayer(root_layer);
158 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]c0dd24c2012-08-30 23:25:27159
[email protected]28571b042013-03-14 07:59:15160 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
161 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
162 test_layer->RemoveFromParent();
163 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]c0dd24c2012-08-30 23:25:27164
[email protected]28571b042013-03-14 07:59:15165 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
166 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
167 child_layer->AddChild(test_layer);
168 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]c0dd24c2012-08-30 23:25:27169
[email protected]28571b042013-03-14 07:59:15170 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
171 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
172 test_layer->SetTextureId(1);
173 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]c0dd24c2012-08-30 23:25:27174
[email protected]28571b042013-03-14 07:59:15175 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AtLeast(1));
176 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
177 test_layer->RemoveFromParent();
178 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]c0dd24c2012-08-30 23:25:27179}
180
[email protected]de44a152013-01-08 15:28:46181class MockMailboxCallback {
[email protected]28571b042013-03-14 07:59:15182 public:
183 MOCK_METHOD2(Release, void(const std::string& mailbox, unsigned sync_point));
[email protected]de44a152013-01-08 15:28:46184};
185
186struct CommonMailboxObjects {
[email protected]28571b042013-03-14 07:59:15187 CommonMailboxObjects()
188 : mailbox_name1_(64, '1'),
189 mailbox_name2_(64, '2'),
190 sync_point1_(1),
191 sync_point2_(2) {
192 release_mailbox1_ = base::Bind(&MockMailboxCallback::Release,
193 base::Unretained(&mock_callback_),
194 mailbox_name1_);
195 release_mailbox2_ = base::Bind(&MockMailboxCallback::Release,
196 base::Unretained(&mock_callback_),
197 mailbox_name2_);
198 gpu::Mailbox m1;
199 m1.SetName(reinterpret_cast<const int8*>(mailbox_name1_.data()));
200 mailbox1_ = TextureMailbox(m1, release_mailbox1_, sync_point1_);
201 gpu::Mailbox m2;
202 m2.SetName(reinterpret_cast<const int8*>(mailbox_name2_.data()));
203 mailbox2_ = TextureMailbox(m2, release_mailbox2_, sync_point2_);
204 }
[email protected]de44a152013-01-08 15:28:46205
[email protected]28571b042013-03-14 07:59:15206 std::string mailbox_name1_;
207 std::string mailbox_name2_;
208 MockMailboxCallback mock_callback_;
209 TextureMailbox::ReleaseCallback release_mailbox1_;
210 TextureMailbox::ReleaseCallback release_mailbox2_;
211 TextureMailbox mailbox1_;
212 TextureMailbox mailbox2_;
213 unsigned sync_point1_;
214 unsigned sync_point2_;
[email protected]de44a152013-01-08 15:28:46215};
216
217class TextureLayerWithMailboxTest : public TextureLayerTest {
[email protected]28571b042013-03-14 07:59:15218 protected:
219 virtual void TearDown() {
220 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
221 EXPECT_CALL(test_data_.mock_callback_,
222 Release(test_data_.mailbox_name1_,
223 test_data_.sync_point1_)).Times(1);
224 TextureLayerTest::TearDown();
225 }
[email protected]de44a152013-01-08 15:28:46226
[email protected]28571b042013-03-14 07:59:15227 CommonMailboxObjects test_data_;
[email protected]de44a152013-01-08 15:28:46228};
229
[email protected]28571b042013-03-14 07:59:15230TEST_F(TextureLayerWithMailboxTest, ReplaceMailboxOnMainThreadBeforeCommit) {
231 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox();
232 ASSERT_TRUE(test_layer);
[email protected]de44a152013-01-08 15:28:46233
[email protected]28571b042013-03-14 07:59:15234 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
235 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
236 layer_tree_host_->SetRootLayer(test_layer);
237 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]de44a152013-01-08 15:28:46238
[email protected]28571b042013-03-14 07:59:15239 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
240 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
241 test_layer->SetTextureMailbox(test_data_.mailbox1_);
242 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]de44a152013-01-08 15:28:46243
[email protected]28571b042013-03-14 07:59:15244 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
245 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
246 EXPECT_CALL(test_data_.mock_callback_,
247 Release(test_data_.mailbox_name1_, test_data_.sync_point1_))
248 .Times(1);
249 test_layer->SetTextureMailbox(test_data_.mailbox2_);
250 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
251 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]de44a152013-01-08 15:28:46252
[email protected]28571b042013-03-14 07:59:15253 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
254 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
255 EXPECT_CALL(test_data_.mock_callback_,
256 Release(test_data_.mailbox_name2_, test_data_.sync_point2_))
257 .Times(1);
258 test_layer->SetTextureMailbox(TextureMailbox());
259 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
260 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]de44a152013-01-08 15:28:46261
[email protected]28571b042013-03-14 07:59:15262 // Test destructor.
263 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
264 test_layer->SetTextureMailbox(test_data_.mailbox1_);
[email protected]de44a152013-01-08 15:28:46265}
266
267class TextureLayerImplWithMailboxThreadedCallback : public ThreadedTest {
[email protected]28571b042013-03-14 07:59:15268 public:
269 TextureLayerImplWithMailboxThreadedCallback()
270 : callback_count_(0),
271 commit_count_(0) {}
272
273 // Make sure callback is received on main and doesn't block the impl thread.
274 void ReleaseCallback(unsigned sync_point) {
275 EXPECT_EQ(true, proxy()->IsMainThread());
276 ++callback_count_;
277 }
278
279 void SetMailbox(char mailbox_char) {
280 TextureMailbox mailbox(
281 std::string(64, mailbox_char),
282 base::Bind(
283 &TextureLayerImplWithMailboxThreadedCallback::ReleaseCallback,
284 base::Unretained(this)));
285 layer_->SetTextureMailbox(mailbox);
286 }
287
288 virtual void beginTest() OVERRIDE {
289 gfx::Size bounds(100, 100);
290 root_ = Layer::Create();
291 root_->SetAnchorPoint(gfx::PointF());
292 root_->SetBounds(bounds);
293
294 layer_ = TextureLayer::CreateForMailbox();
295 layer_->SetIsDrawable(true);
296 layer_->SetAnchorPoint(gfx::PointF());
297 layer_->SetBounds(bounds);
298
299 root_->AddChild(layer_);
300 m_layerTreeHost->SetRootLayer(root_);
301 m_layerTreeHost->SetViewportSize(bounds, bounds);
302 SetMailbox('1');
303 EXPECT_EQ(0, callback_count_);
304
305 // Case #1: change mailbox before the commit. The old mailbox should be
306 // released immediately.
307 SetMailbox('2');
308 EXPECT_EQ(1, callback_count_);
309 postSetNeedsCommitToMainThread();
310 }
311
312 virtual void didCommit() OVERRIDE {
313 ++commit_count_;
314 switch (commit_count_) {
315 case 1:
316 // Case #2: change mailbox after the commit (and draw), where the
317 // layer draws. The old mailbox should be released during the next
318 // commit.
319 SetMailbox('3');
320 EXPECT_EQ(1, callback_count_);
321 break;
322 case 2:
323 // Old mailbox was released, task was posted, but won't execute
324 // until this didCommit returns.
325 // TODO(piman): fix this.
326 EXPECT_EQ(1, callback_count_);
327 m_layerTreeHost->SetNeedsCommit();
328 break;
329 case 3:
330 EXPECT_EQ(2, callback_count_);
331 // Case #3: change mailbox when the layer doesn't draw. The old
332 // mailbox should be released during the next commit.
333 layer_->SetBounds(gfx::Size());
334 SetMailbox('4');
335 break;
336 case 4:
337 // Old mailbox was released, task was posted, but won't execute
338 // until this didCommit returns.
339 // TODO(piman): fix this.
340 EXPECT_EQ(2, callback_count_);
341 m_layerTreeHost->SetNeedsCommit();
342 break;
343 case 5:
344 EXPECT_EQ(3, callback_count_);
345 // Case #4: release mailbox that was committed but never drawn. The
346 // old mailbox should be released during the next commit.
347 layer_->SetTextureMailbox(TextureMailbox());
348 break;
349 case 6:
350 // Old mailbox was released, task was posted, but won't execute
351 // until this didCommit returns.
352 // TODO(piman): fix this.
353 EXPECT_EQ(3, callback_count_);
354 m_layerTreeHost->SetNeedsCommit();
355 break;
356 case 7:
357 EXPECT_EQ(4, callback_count_);
358 endTest();
359 break;
360 default:
361 NOTREACHED();
362 break;
[email protected]de44a152013-01-08 15:28:46363 }
[email protected]28571b042013-03-14 07:59:15364 }
[email protected]de44a152013-01-08 15:28:46365
[email protected]28571b042013-03-14 07:59:15366 virtual void afterTest() OVERRIDE {}
[email protected]de44a152013-01-08 15:28:46367
[email protected]28571b042013-03-14 07:59:15368 private:
369 int callback_count_;
370 int commit_count_;
371 scoped_refptr<Layer> root_;
372 scoped_refptr<TextureLayer> layer_;
[email protected]de44a152013-01-08 15:28:46373};
374
375SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerImplWithMailboxThreadedCallback);
376
377class TextureLayerImplWithMailboxTest : public TextureLayerTest {
[email protected]28571b042013-03-14 07:59:15378 protected:
379 virtual void SetUp() {
380 TextureLayerTest::SetUp();
381 layer_tree_host_.reset(new MockLayerImplTreeHost);
382 EXPECT_TRUE(host_impl_.InitializeRenderer(createFakeOutputSurface()));
383 }
[email protected]de44a152013-01-08 15:28:46384
[email protected]28571b042013-03-14 07:59:15385 CommonMailboxObjects test_data_;
[email protected]de44a152013-01-08 15:28:46386};
387
[email protected]28571b042013-03-14 07:59:15388TEST_F(TextureLayerImplWithMailboxTest, TestImplLayerCallbacks) {
389 host_impl_.CreatePendingTree();
390 scoped_ptr<TextureLayerImpl> pending_layer;
391 pending_layer = TextureLayerImpl::Create(host_impl_.pending_tree(), 1, true);
392 ASSERT_TRUE(pending_layer);
[email protected]de44a152013-01-08 15:28:46393
[email protected]28571b042013-03-14 07:59:15394 scoped_ptr<LayerImpl> activeLayer(
395 pending_layer->CreateLayerImpl(host_impl_.active_tree()));
396 ASSERT_TRUE(activeLayer);
[email protected]de44a152013-01-08 15:28:46397
[email protected]1a37a0752013-03-17 21:25:49398 pending_layer->SetTextureMailbox(test_data_.mailbox1_);
[email protected]421e84f2013-02-22 03:27:15399
[email protected]28571b042013-03-14 07:59:15400 // Test multiple commits without an activation.
401 EXPECT_CALL(test_data_.mock_callback_,
402 Release(test_data_.mailbox_name1_, test_data_.sync_point1_))
403 .Times(1);
[email protected]1a37a0752013-03-17 21:25:49404 pending_layer->SetTextureMailbox(test_data_.mailbox2_);
[email protected]28571b042013-03-14 07:59:15405 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]421e84f2013-02-22 03:27:15406
[email protected]28571b042013-03-14 07:59:15407 // Test callback after activation.
408 pending_layer->PushPropertiesTo(activeLayer.get());
409 activeLayer->DidBecomeActive();
[email protected]421e84f2013-02-22 03:27:15410
[email protected]28571b042013-03-14 07:59:15411 EXPECT_CALL(test_data_.mock_callback_, Release(_, _)).Times(0);
[email protected]1a37a0752013-03-17 21:25:49412 pending_layer->SetTextureMailbox(test_data_.mailbox1_);
[email protected]28571b042013-03-14 07:59:15413 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]421e84f2013-02-22 03:27:15414
[email protected]28571b042013-03-14 07:59:15415 EXPECT_CALL(test_data_.mock_callback_, Release(test_data_.mailbox_name2_, _))
416 .Times(1);
417 pending_layer->PushPropertiesTo(activeLayer.get());
418 activeLayer->DidBecomeActive();
419 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]de44a152013-01-08 15:28:46420
[email protected]28571b042013-03-14 07:59:15421 // Test resetting the mailbox.
422 EXPECT_CALL(test_data_.mock_callback_, Release(test_data_.mailbox_name1_, _))
423 .Times(1);
[email protected]1a37a0752013-03-17 21:25:49424 pending_layer->SetTextureMailbox(TextureMailbox());
[email protected]28571b042013-03-14 07:59:15425 pending_layer->PushPropertiesTo(activeLayer.get());
426 activeLayer->DidBecomeActive();
427 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]de44a152013-01-08 15:28:46428
[email protected]28571b042013-03-14 07:59:15429 // Test destructor.
430 EXPECT_CALL(test_data_.mock_callback_,
431 Release(test_data_.mailbox_name1_, test_data_.sync_point1_))
432 .Times(1);
[email protected]1a37a0752013-03-17 21:25:49433 pending_layer->SetTextureMailbox(test_data_.mailbox1_);
[email protected]de44a152013-01-08 15:28:46434}
435
[email protected]28571b042013-03-14 07:59:15436TEST_F(TextureLayerImplWithMailboxTest,
437 TestDestructorCallbackOnCreatedResource) {
438 scoped_ptr<TextureLayerImpl> impl_layer;
439 impl_layer = TextureLayerImpl::Create(host_impl_.active_tree(), 1, true);
440 ASSERT_TRUE(impl_layer);
[email protected]de44a152013-01-08 15:28:46441
[email protected]28571b042013-03-14 07:59:15442 EXPECT_CALL(test_data_.mock_callback_, Release(test_data_.mailbox_name1_, _))
443 .Times(1);
[email protected]1a37a0752013-03-17 21:25:49444 impl_layer->SetTextureMailbox(test_data_.mailbox1_);
[email protected]28571b042013-03-14 07:59:15445 impl_layer->WillDraw(host_impl_.active_tree()->resource_provider());
446 impl_layer->DidDraw(host_impl_.active_tree()->resource_provider());
[email protected]1a37a0752013-03-17 21:25:49447 impl_layer->SetTextureMailbox(TextureMailbox());
[email protected]de44a152013-01-08 15:28:46448}
449
[email protected]28571b042013-03-14 07:59:15450TEST_F(TextureLayerImplWithMailboxTest, TestCallbackOnInUseResource) {
451 ResourceProvider* provider = host_impl_.active_tree()->resource_provider();
452 ResourceProvider::ResourceId id =
453 provider->CreateResourceFromTextureMailbox(test_data_.mailbox1_);
454 provider->AllocateForTesting(id);
[email protected]de44a152013-01-08 15:28:46455
[email protected]28571b042013-03-14 07:59:15456 // Transfer some resources to the parent.
457 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
458 resource_ids_to_transfer.push_back(id);
459 TransferableResourceArray list;
460 provider->PrepareSendToParent(resource_ids_to_transfer, &list);
461 EXPECT_TRUE(provider->InUseByConsumer(id));
462 EXPECT_CALL(test_data_.mock_callback_, Release(_, _)).Times(0);
463 provider->DeleteResource(id);
464 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
465 EXPECT_CALL(test_data_.mock_callback_, Release(test_data_.mailbox_name1_, _))
466 .Times(1);
467 provider->ReceiveFromParent(list);
[email protected]de44a152013-01-08 15:28:46468}
469
[email protected]ba565742012-11-10 09:29:48470} // namespace
471} // namespace cc