blob: 6d2098800ac017e9c7ddbce6fe6c72da75400c10 [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]cc3cfaa2013-03-18 09:05:525#include "cc/layers/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]cc3cfaa2013-03-18 09:05:5211#include "cc/layers/texture_layer_impl.h"
[email protected]586d51ed2012-12-07 20:31:4512#include "cc/test/fake_impl_proxy.h"
[email protected]101441ce2012-10-16 01:45:0313#include "cc/test/fake_layer_tree_host_client.h"
[email protected]586d51ed2012-12-07 20:31:4514#include "cc/test/fake_layer_tree_host_impl.h"
[email protected]e216fef02013-03-20 22:56:1015#include "cc/test/layer_tree_test.h"
[email protected]556fd292013-03-18 08:03:0416#include "cc/trees/layer_tree_host.h"
17#include "cc/trees/layer_tree_impl.h"
18#include "cc/trees/single_thread_proxy.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]408b5e22013-03-19 09:48:0930class MockLayerTreeHost : public LayerTreeHost {
[email protected]28571b042013-03-14 07:59:1531 public:
[email protected]bf691c22013-03-26 21:15:0632 explicit MockLayerTreeHost(LayerTreeHostClient* client)
[email protected]408b5e22013-03-19 09:48:0933 : LayerTreeHost(client, LayerTreeSettings()) {
[email protected]28571b042013-03-14 07:59:1534 Initialize(scoped_ptr<Thread>(NULL));
35 }
[email protected]c0dd24c2012-08-30 23:25:2736
[email protected]28571b042013-03-14 07:59:1537 MOCK_METHOD0(AcquireLayerTextures, void());
38 MOCK_METHOD0(SetNeedsCommit, void());
[email protected]c0dd24c2012-08-30 23:25:2739};
40
[email protected]96baf3e2012-10-22 23:09:5541class TextureLayerTest : public testing::Test {
[email protected]28571b042013-03-14 07:59:1542 public:
[email protected]408b5e22013-03-19 09:48:0943 TextureLayerTest()
44 : fake_client_(
45 FakeLayerTreeHostClient(FakeLayerTreeHostClient::DIRECT_3D)),
46 host_impl_(&proxy_) {}
[email protected]0f077a52012-09-08 01:45:2447
[email protected]28571b042013-03-14 07:59:1548 protected:
49 virtual void SetUp() {
[email protected]408b5e22013-03-19 09:48:0950 layer_tree_host_.reset(new MockLayerTreeHost(&fake_client_));
[email protected]28571b042013-03-14 07:59:1551 }
[email protected]c0dd24c2012-08-30 23:25:2752
[email protected]28571b042013-03-14 07:59:1553 virtual void TearDown() {
54 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
55 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber());
56 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
[email protected]c0dd24c2012-08-30 23:25:2757
[email protected]28571b042013-03-14 07:59:1558 layer_tree_host_->SetRootLayer(NULL);
59 layer_tree_host_.reset();
60 }
[email protected]c0dd24c2012-08-30 23:25:2761
[email protected]408b5e22013-03-19 09:48:0962 scoped_ptr<MockLayerTreeHost> layer_tree_host_;
[email protected]28571b042013-03-14 07:59:1563 FakeImplProxy proxy_;
[email protected]408b5e22013-03-19 09:48:0964 FakeLayerTreeHostClient fake_client_;
[email protected]28571b042013-03-14 07:59:1565 FakeLayerTreeHostImpl host_impl_;
[email protected]c0dd24c2012-08-30 23:25:2766};
67
[email protected]28571b042013-03-14 07:59:1568TEST_F(TextureLayerTest, SyncImplWhenChangingTextureId) {
69 scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(NULL);
70 ASSERT_TRUE(test_layer);
[email protected]c0dd24c2012-08-30 23:25:2771
[email protected]28571b042013-03-14 07:59:1572 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber());
73 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
74 layer_tree_host_->SetRootLayer(test_layer);
75 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
76 EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get());
[email protected]c0dd24c2012-08-30 23:25:2777
[email protected]28571b042013-03-14 07:59:1578 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
79 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
80 test_layer->SetTextureId(1);
81 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]c0dd24c2012-08-30 23:25:2782
[email protected]28571b042013-03-14 07:59:1583 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AtLeast(1));
84 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
85 test_layer->SetTextureId(2);
86 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]c0dd24c2012-08-30 23:25:2787
[email protected]28571b042013-03-14 07:59:1588 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AtLeast(1));
89 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
90 test_layer->SetTextureId(0);
91 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]c0dd24c2012-08-30 23:25:2792}
93
[email protected]28571b042013-03-14 07:59:1594TEST_F(TextureLayerTest, SyncImplWhenDrawing) {
95 gfx::RectF dirty_rect(0.f, 0.f, 1.f, 1.f);
[email protected]031ccfff2012-10-26 00:57:3896
[email protected]28571b042013-03-14 07:59:1597 scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(NULL);
98 ASSERT_TRUE(test_layer);
99 scoped_ptr<TextureLayerImpl> impl_layer;
100 impl_layer = TextureLayerImpl::Create(host_impl_.active_tree(), 1, false);
101 ASSERT_TRUE(impl_layer);
[email protected]031ccfff2012-10-26 00:57:38102
[email protected]28571b042013-03-14 07:59:15103 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber());
104 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
105 layer_tree_host_->SetRootLayer(test_layer);
106 test_layer->SetTextureId(1);
107 test_layer->SetIsDrawable(true);
108 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
109 EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get());
[email protected]031ccfff2012-10-26 00:57:38110
[email protected]28571b042013-03-14 07:59:15111 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(1);
112 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0);
113 test_layer->WillModifyTexture();
114 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]031ccfff2012-10-26 00:57:38115
[email protected]28571b042013-03-14 07:59:15116 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
117 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1);
118 test_layer->SetNeedsDisplayRect(dirty_rect);
119 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]031ccfff2012-10-26 00:57:38120
[email protected]28571b042013-03-14 07:59:15121 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
122 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1);
123 test_layer->PushPropertiesTo(impl_layer.get()); // fake commit
124 test_layer->SetIsDrawable(false);
125 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]031ccfff2012-10-26 00:57:38126
[email protected]28571b042013-03-14 07:59:15127 // Verify that non-drawable layers don't signal the compositor,
128 // except for the first draw after last commit, which must acquire
129 // the texture.
130 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(1);
131 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0);
132 test_layer->WillModifyTexture();
133 test_layer->SetNeedsDisplayRect(dirty_rect);
134 test_layer->PushPropertiesTo(impl_layer.get()); // fake commit
135 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]031ccfff2012-10-26 00:57:38136
[email protected]28571b042013-03-14 07:59:15137 // Second draw with layer in non-drawable state: no texture
138 // acquisition.
139 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
140 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0);
141 test_layer->WillModifyTexture();
142 test_layer->SetNeedsDisplayRect(dirty_rect);
143 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]031ccfff2012-10-26 00:57:38144}
145
[email protected]28571b042013-03-14 07:59:15146TEST_F(TextureLayerTest, SyncImplWhenRemovingFromTree) {
147 scoped_refptr<Layer> root_layer = Layer::Create();
148 ASSERT_TRUE(root_layer);
149 scoped_refptr<Layer> child_layer = Layer::Create();
150 ASSERT_TRUE(child_layer);
151 root_layer->AddChild(child_layer);
152 scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(NULL);
153 ASSERT_TRUE(test_layer);
154 test_layer->SetTextureId(0);
155 child_layer->AddChild(test_layer);
[email protected]c0dd24c2012-08-30 23:25:27156
[email protected]28571b042013-03-14 07:59:15157 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber());
158 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
159 layer_tree_host_->SetRootLayer(root_layer);
160 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]c0dd24c2012-08-30 23:25:27161
[email protected]28571b042013-03-14 07:59:15162 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
163 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
164 test_layer->RemoveFromParent();
165 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]c0dd24c2012-08-30 23:25:27166
[email protected]28571b042013-03-14 07:59:15167 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
168 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
169 child_layer->AddChild(test_layer);
170 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]c0dd24c2012-08-30 23:25:27171
[email protected]28571b042013-03-14 07:59:15172 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
173 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
174 test_layer->SetTextureId(1);
175 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]c0dd24c2012-08-30 23:25:27176
[email protected]28571b042013-03-14 07:59:15177 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AtLeast(1));
178 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
179 test_layer->RemoveFromParent();
180 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]c0dd24c2012-08-30 23:25:27181}
182
[email protected]de44a152013-01-08 15:28:46183class MockMailboxCallback {
[email protected]28571b042013-03-14 07:59:15184 public:
185 MOCK_METHOD2(Release, void(const std::string& mailbox, unsigned sync_point));
[email protected]de44a152013-01-08 15:28:46186};
187
188struct CommonMailboxObjects {
[email protected]28571b042013-03-14 07:59:15189 CommonMailboxObjects()
190 : mailbox_name1_(64, '1'),
191 mailbox_name2_(64, '2'),
192 sync_point1_(1),
193 sync_point2_(2) {
194 release_mailbox1_ = base::Bind(&MockMailboxCallback::Release,
195 base::Unretained(&mock_callback_),
196 mailbox_name1_);
197 release_mailbox2_ = base::Bind(&MockMailboxCallback::Release,
198 base::Unretained(&mock_callback_),
199 mailbox_name2_);
200 gpu::Mailbox m1;
201 m1.SetName(reinterpret_cast<const int8*>(mailbox_name1_.data()));
202 mailbox1_ = TextureMailbox(m1, release_mailbox1_, sync_point1_);
203 gpu::Mailbox m2;
204 m2.SetName(reinterpret_cast<const int8*>(mailbox_name2_.data()));
205 mailbox2_ = TextureMailbox(m2, release_mailbox2_, sync_point2_);
206 }
[email protected]de44a152013-01-08 15:28:46207
[email protected]28571b042013-03-14 07:59:15208 std::string mailbox_name1_;
209 std::string mailbox_name2_;
210 MockMailboxCallback mock_callback_;
211 TextureMailbox::ReleaseCallback release_mailbox1_;
212 TextureMailbox::ReleaseCallback release_mailbox2_;
213 TextureMailbox mailbox1_;
214 TextureMailbox mailbox2_;
215 unsigned sync_point1_;
216 unsigned sync_point2_;
[email protected]de44a152013-01-08 15:28:46217};
218
219class TextureLayerWithMailboxTest : public TextureLayerTest {
[email protected]28571b042013-03-14 07:59:15220 protected:
221 virtual void TearDown() {
222 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
223 EXPECT_CALL(test_data_.mock_callback_,
224 Release(test_data_.mailbox_name1_,
225 test_data_.sync_point1_)).Times(1);
226 TextureLayerTest::TearDown();
227 }
[email protected]de44a152013-01-08 15:28:46228
[email protected]28571b042013-03-14 07:59:15229 CommonMailboxObjects test_data_;
[email protected]de44a152013-01-08 15:28:46230};
231
[email protected]28571b042013-03-14 07:59:15232TEST_F(TextureLayerWithMailboxTest, ReplaceMailboxOnMainThreadBeforeCommit) {
233 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox();
234 ASSERT_TRUE(test_layer);
[email protected]de44a152013-01-08 15:28:46235
[email protected]28571b042013-03-14 07:59:15236 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
237 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
238 layer_tree_host_->SetRootLayer(test_layer);
239 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]de44a152013-01-08 15:28:46240
[email protected]28571b042013-03-14 07:59:15241 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
242 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
243 test_layer->SetTextureMailbox(test_data_.mailbox1_);
244 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
[email protected]de44a152013-01-08 15:28:46245
[email protected]28571b042013-03-14 07:59:15246 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
247 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
248 EXPECT_CALL(test_data_.mock_callback_,
249 Release(test_data_.mailbox_name1_, test_data_.sync_point1_))
250 .Times(1);
251 test_layer->SetTextureMailbox(test_data_.mailbox2_);
252 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
253 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]de44a152013-01-08 15:28:46254
[email protected]28571b042013-03-14 07:59:15255 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
256 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
257 EXPECT_CALL(test_data_.mock_callback_,
258 Release(test_data_.mailbox_name2_, test_data_.sync_point2_))
259 .Times(1);
260 test_layer->SetTextureMailbox(TextureMailbox());
261 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
262 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]de44a152013-01-08 15:28:46263
[email protected]28571b042013-03-14 07:59:15264 // Test destructor.
265 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
266 test_layer->SetTextureMailbox(test_data_.mailbox1_);
[email protected]de44a152013-01-08 15:28:46267}
268
[email protected]e216fef02013-03-20 22:56:10269class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest {
[email protected]28571b042013-03-14 07:59:15270 public:
271 TextureLayerImplWithMailboxThreadedCallback()
272 : callback_count_(0),
273 commit_count_(0) {}
274
275 // Make sure callback is received on main and doesn't block the impl thread.
276 void ReleaseCallback(unsigned sync_point) {
277 EXPECT_EQ(true, proxy()->IsMainThread());
278 ++callback_count_;
279 }
280
281 void SetMailbox(char mailbox_char) {
282 TextureMailbox mailbox(
283 std::string(64, mailbox_char),
284 base::Bind(
285 &TextureLayerImplWithMailboxThreadedCallback::ReleaseCallback,
286 base::Unretained(this)));
287 layer_->SetTextureMailbox(mailbox);
288 }
289
[email protected]e216fef02013-03-20 22:56:10290 virtual void BeginTest() OVERRIDE {
[email protected]28571b042013-03-14 07:59:15291 gfx::Size bounds(100, 100);
292 root_ = Layer::Create();
293 root_->SetAnchorPoint(gfx::PointF());
294 root_->SetBounds(bounds);
295
296 layer_ = TextureLayer::CreateForMailbox();
297 layer_->SetIsDrawable(true);
298 layer_->SetAnchorPoint(gfx::PointF());
299 layer_->SetBounds(bounds);
300
301 root_->AddChild(layer_);
[email protected]e216fef02013-03-20 22:56:10302 layer_tree_host()->SetRootLayer(root_);
303 layer_tree_host()->SetViewportSize(bounds, bounds);
[email protected]28571b042013-03-14 07:59:15304 SetMailbox('1');
305 EXPECT_EQ(0, callback_count_);
306
307 // Case #1: change mailbox before the commit. The old mailbox should be
308 // released immediately.
309 SetMailbox('2');
310 EXPECT_EQ(1, callback_count_);
[email protected]e216fef02013-03-20 22:56:10311 PostSetNeedsCommitToMainThread();
[email protected]28571b042013-03-14 07:59:15312 }
313
[email protected]e216fef02013-03-20 22:56:10314 virtual void DidCommit() OVERRIDE {
[email protected]28571b042013-03-14 07:59:15315 ++commit_count_;
316 switch (commit_count_) {
317 case 1:
318 // Case #2: change mailbox after the commit (and draw), where the
319 // layer draws. The old mailbox should be released during the next
320 // commit.
321 SetMailbox('3');
322 EXPECT_EQ(1, callback_count_);
323 break;
324 case 2:
325 // Old mailbox was released, task was posted, but won't execute
[email protected]ed511b8d2013-03-25 03:29:29326 // until this DidCommit returns.
[email protected]28571b042013-03-14 07:59:15327 // TODO(piman): fix this.
328 EXPECT_EQ(1, callback_count_);
[email protected]e216fef02013-03-20 22:56:10329 layer_tree_host()->SetNeedsCommit();
[email protected]28571b042013-03-14 07:59:15330 break;
331 case 3:
332 EXPECT_EQ(2, callback_count_);
333 // Case #3: change mailbox when the layer doesn't draw. The old
334 // mailbox should be released during the next commit.
335 layer_->SetBounds(gfx::Size());
336 SetMailbox('4');
337 break;
338 case 4:
339 // Old mailbox was released, task was posted, but won't execute
[email protected]ed511b8d2013-03-25 03:29:29340 // until this DidCommit returns.
[email protected]28571b042013-03-14 07:59:15341 // TODO(piman): fix this.
342 EXPECT_EQ(2, callback_count_);
[email protected]e216fef02013-03-20 22:56:10343 layer_tree_host()->SetNeedsCommit();
[email protected]28571b042013-03-14 07:59:15344 break;
345 case 5:
346 EXPECT_EQ(3, callback_count_);
347 // Case #4: release mailbox that was committed but never drawn. The
348 // old mailbox should be released during the next commit.
349 layer_->SetTextureMailbox(TextureMailbox());
350 break;
351 case 6:
352 // Old mailbox was released, task was posted, but won't execute
[email protected]ed511b8d2013-03-25 03:29:29353 // until this DidCommit returns.
[email protected]28571b042013-03-14 07:59:15354 // TODO(piman): fix this.
355 EXPECT_EQ(3, callback_count_);
[email protected]e216fef02013-03-20 22:56:10356 layer_tree_host()->SetNeedsCommit();
[email protected]28571b042013-03-14 07:59:15357 break;
358 case 7:
359 EXPECT_EQ(4, callback_count_);
[email protected]e216fef02013-03-20 22:56:10360 EndTest();
[email protected]28571b042013-03-14 07:59:15361 break;
362 default:
363 NOTREACHED();
364 break;
[email protected]de44a152013-01-08 15:28:46365 }
[email protected]28571b042013-03-14 07:59:15366 }
[email protected]de44a152013-01-08 15:28:46367
[email protected]e216fef02013-03-20 22:56:10368 virtual void AfterTest() OVERRIDE {}
[email protected]de44a152013-01-08 15:28:46369
[email protected]28571b042013-03-14 07:59:15370 private:
371 int callback_count_;
372 int commit_count_;
373 scoped_refptr<Layer> root_;
374 scoped_refptr<TextureLayer> layer_;
[email protected]de44a152013-01-08 15:28:46375};
376
377SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerImplWithMailboxThreadedCallback);
378
379class TextureLayerImplWithMailboxTest : public TextureLayerTest {
[email protected]28571b042013-03-14 07:59:15380 protected:
[email protected]408b5e22013-03-19 09:48:09381 TextureLayerImplWithMailboxTest()
382 : fake_client_(
383 FakeLayerTreeHostClient(FakeLayerTreeHostClient::DIRECT_3D)) {}
384
[email protected]28571b042013-03-14 07:59:15385 virtual void SetUp() {
386 TextureLayerTest::SetUp();
[email protected]408b5e22013-03-19 09:48:09387 layer_tree_host_.reset(new MockLayerTreeHost(&fake_client_));
[email protected]f74945f2013-03-21 17:08:36388 EXPECT_TRUE(host_impl_.InitializeRenderer(CreateFakeOutputSurface()));
[email protected]28571b042013-03-14 07:59:15389 }
[email protected]de44a152013-01-08 15:28:46390
[email protected]28571b042013-03-14 07:59:15391 CommonMailboxObjects test_data_;
[email protected]408b5e22013-03-19 09:48:09392 FakeLayerTreeHostClient fake_client_;
[email protected]de44a152013-01-08 15:28:46393};
394
[email protected]28571b042013-03-14 07:59:15395TEST_F(TextureLayerImplWithMailboxTest, TestImplLayerCallbacks) {
396 host_impl_.CreatePendingTree();
397 scoped_ptr<TextureLayerImpl> pending_layer;
398 pending_layer = TextureLayerImpl::Create(host_impl_.pending_tree(), 1, true);
399 ASSERT_TRUE(pending_layer);
[email protected]de44a152013-01-08 15:28:46400
[email protected]ed511b8d2013-03-25 03:29:29401 scoped_ptr<LayerImpl> active_layer(
[email protected]28571b042013-03-14 07:59:15402 pending_layer->CreateLayerImpl(host_impl_.active_tree()));
[email protected]ed511b8d2013-03-25 03:29:29403 ASSERT_TRUE(active_layer);
[email protected]de44a152013-01-08 15:28:46404
[email protected]1a37a0752013-03-17 21:25:49405 pending_layer->SetTextureMailbox(test_data_.mailbox1_);
[email protected]421e84f2013-02-22 03:27:15406
[email protected]28571b042013-03-14 07:59:15407 // Test multiple commits without an activation.
408 EXPECT_CALL(test_data_.mock_callback_,
409 Release(test_data_.mailbox_name1_, test_data_.sync_point1_))
410 .Times(1);
[email protected]1a37a0752013-03-17 21:25:49411 pending_layer->SetTextureMailbox(test_data_.mailbox2_);
[email protected]28571b042013-03-14 07:59:15412 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]421e84f2013-02-22 03:27:15413
[email protected]28571b042013-03-14 07:59:15414 // Test callback after activation.
[email protected]ed511b8d2013-03-25 03:29:29415 pending_layer->PushPropertiesTo(active_layer.get());
416 active_layer->DidBecomeActive();
[email protected]421e84f2013-02-22 03:27:15417
[email protected]28571b042013-03-14 07:59:15418 EXPECT_CALL(test_data_.mock_callback_, Release(_, _)).Times(0);
[email protected]1a37a0752013-03-17 21:25:49419 pending_layer->SetTextureMailbox(test_data_.mailbox1_);
[email protected]28571b042013-03-14 07:59:15420 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]421e84f2013-02-22 03:27:15421
[email protected]28571b042013-03-14 07:59:15422 EXPECT_CALL(test_data_.mock_callback_, Release(test_data_.mailbox_name2_, _))
423 .Times(1);
[email protected]ed511b8d2013-03-25 03:29:29424 pending_layer->PushPropertiesTo(active_layer.get());
425 active_layer->DidBecomeActive();
[email protected]28571b042013-03-14 07:59:15426 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]de44a152013-01-08 15:28:46427
[email protected]28571b042013-03-14 07:59:15428 // Test resetting the mailbox.
429 EXPECT_CALL(test_data_.mock_callback_, Release(test_data_.mailbox_name1_, _))
430 .Times(1);
[email protected]1a37a0752013-03-17 21:25:49431 pending_layer->SetTextureMailbox(TextureMailbox());
[email protected]ed511b8d2013-03-25 03:29:29432 pending_layer->PushPropertiesTo(active_layer.get());
433 active_layer->DidBecomeActive();
[email protected]28571b042013-03-14 07:59:15434 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
[email protected]de44a152013-01-08 15:28:46435
[email protected]28571b042013-03-14 07:59:15436 // Test destructor.
437 EXPECT_CALL(test_data_.mock_callback_,
438 Release(test_data_.mailbox_name1_, test_data_.sync_point1_))
439 .Times(1);
[email protected]1a37a0752013-03-17 21:25:49440 pending_layer->SetTextureMailbox(test_data_.mailbox1_);
[email protected]de44a152013-01-08 15:28:46441}
442
[email protected]28571b042013-03-14 07:59:15443TEST_F(TextureLayerImplWithMailboxTest,
444 TestDestructorCallbackOnCreatedResource) {
445 scoped_ptr<TextureLayerImpl> impl_layer;
446 impl_layer = TextureLayerImpl::Create(host_impl_.active_tree(), 1, true);
447 ASSERT_TRUE(impl_layer);
[email protected]de44a152013-01-08 15:28:46448
[email protected]28571b042013-03-14 07:59:15449 EXPECT_CALL(test_data_.mock_callback_, Release(test_data_.mailbox_name1_, _))
450 .Times(1);
[email protected]1a37a0752013-03-17 21:25:49451 impl_layer->SetTextureMailbox(test_data_.mailbox1_);
[email protected]28571b042013-03-14 07:59:15452 impl_layer->WillDraw(host_impl_.active_tree()->resource_provider());
453 impl_layer->DidDraw(host_impl_.active_tree()->resource_provider());
[email protected]1a37a0752013-03-17 21:25:49454 impl_layer->SetTextureMailbox(TextureMailbox());
[email protected]de44a152013-01-08 15:28:46455}
456
[email protected]28571b042013-03-14 07:59:15457TEST_F(TextureLayerImplWithMailboxTest, TestCallbackOnInUseResource) {
458 ResourceProvider* provider = host_impl_.active_tree()->resource_provider();
459 ResourceProvider::ResourceId id =
460 provider->CreateResourceFromTextureMailbox(test_data_.mailbox1_);
461 provider->AllocateForTesting(id);
[email protected]de44a152013-01-08 15:28:46462
[email protected]28571b042013-03-14 07:59:15463 // Transfer some resources to the parent.
464 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
465 resource_ids_to_transfer.push_back(id);
466 TransferableResourceArray list;
467 provider->PrepareSendToParent(resource_ids_to_transfer, &list);
468 EXPECT_TRUE(provider->InUseByConsumer(id));
469 EXPECT_CALL(test_data_.mock_callback_, Release(_, _)).Times(0);
470 provider->DeleteResource(id);
471 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_);
472 EXPECT_CALL(test_data_.mock_callback_, Release(test_data_.mailbox_name1_, _))
473 .Times(1);
474 provider->ReceiveFromParent(list);
[email protected]de44a152013-01-08 15:28:46475}
476
[email protected]ba565742012-11-10 09:29:48477} // namespace
478} // namespace cc