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

Side by Side Diff: trunk/src/cc/layers/texture_layer_unittest.cc

Issue 224153003: Revert 261380 "cc: Remove TextureLayer::SetTextureId and Texture..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 8 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 "cc/layers/texture_layer.h" 5 #include "cc/layers/texture_layer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 19 matching lines...) Expand all
30 #include "cc/trees/layer_tree_impl.h" 30 #include "cc/trees/layer_tree_impl.h"
31 #include "cc/trees/single_thread_proxy.h" 31 #include "cc/trees/single_thread_proxy.h"
32 #include "gpu/GLES2/gl2extchromium.h" 32 #include "gpu/GLES2/gl2extchromium.h"
33 #include "testing/gmock/include/gmock/gmock.h" 33 #include "testing/gmock/include/gmock/gmock.h"
34 #include "testing/gtest/include/gtest/gtest.h" 34 #include "testing/gtest/include/gtest/gtest.h"
35 35
36 using ::testing::Mock; 36 using ::testing::Mock;
37 using ::testing::_; 37 using ::testing::_;
38 using ::testing::AtLeast; 38 using ::testing::AtLeast;
39 using ::testing::AnyNumber; 39 using ::testing::AnyNumber;
40 using ::testing::InvokeWithoutArgs;
41 40
42 namespace cc { 41 namespace cc {
43 namespace { 42 namespace {
44 43
45 gpu::Mailbox MailboxFromChar(char value) { 44 gpu::Mailbox MailboxFromChar(char value) {
46 gpu::Mailbox mailbox; 45 gpu::Mailbox mailbox;
47 memset(mailbox.name, value, sizeof(mailbox.name)); 46 memset(mailbox.name, value, sizeof(mailbox.name));
48 return mailbox; 47 return mailbox;
49 } 48 }
50 49
51 class MockLayerTreeHost : public LayerTreeHost { 50 class MockLayerTreeHost : public LayerTreeHost {
52 public: 51 public:
53 explicit MockLayerTreeHost(FakeLayerTreeHostClient* client) 52 explicit MockLayerTreeHost(FakeLayerTreeHostClient* client)
54 : LayerTreeHost(client, NULL, LayerTreeSettings()) { 53 : LayerTreeHost(client, NULL, LayerTreeSettings()) {
55 InitializeSingleThreaded(client); 54 InitializeSingleThreaded(client);
56 } 55 }
57 56
58 MOCK_METHOD0(AcquireLayerTextures, void()); 57 MOCK_METHOD0(AcquireLayerTextures, void());
59 MOCK_METHOD0(SetNeedsCommit, void()); 58 MOCK_METHOD0(SetNeedsCommit, void());
60 MOCK_METHOD0(SetNeedsUpdateLayers, void()); 59 MOCK_METHOD0(SetNeedsUpdateLayers, void());
61 MOCK_METHOD0(StartRateLimiter, void()); 60 MOCK_METHOD0(StartRateLimiter, void());
62 MOCK_METHOD0(StopRateLimiter, void()); 61 MOCK_METHOD0(StopRateLimiter, void());
63 }; 62 };
64 63
65 class FakeTextureLayerClient : public TextureLayerClient {
66 public:
67 FakeTextureLayerClient() : texture_(0), mailbox_changed_(true) {}
68
69 virtual unsigned PrepareTexture() OVERRIDE { return texture_; }
70
71 virtual bool PrepareTextureMailbox(
72 TextureMailbox* mailbox,
73 scoped_ptr<SingleReleaseCallback>* release_callback,
74 bool use_shared_memory) OVERRIDE {
75 if (!mailbox_changed_)
76 return false;
77
78 *mailbox = mailbox_;
79 *release_callback = release_callback_.Pass();
80 mailbox_changed_ = false;
81 return true;
82 }
83
84 void set_texture(unsigned texture) { texture_ = texture; }
85
86 void set_mailbox(const TextureMailbox& mailbox,
87 scoped_ptr<SingleReleaseCallback> release_callback) {
88 mailbox_ = mailbox;
89 release_callback_ = release_callback.Pass();
90 mailbox_changed_ = true;
91 }
92
93 private:
94 unsigned texture_;
95 TextureMailbox mailbox_;
96 scoped_ptr<SingleReleaseCallback> release_callback_;
97 bool mailbox_changed_;
98 DISALLOW_COPY_AND_ASSIGN(FakeTextureLayerClient);
99 };
100
101 class MockMailboxCallback {
102 public:
103 MOCK_METHOD3(Release,
104 void(const gpu::Mailbox& mailbox,
105 uint32 sync_point,
106 bool lost_resource));
107 MOCK_METHOD3(Release2,
108 void(base::SharedMemory* shared_memory,
109 uint32 sync_point,
110 bool lost_resource));
111 };
112
113 struct CommonMailboxObjects {
114 CommonMailboxObjects()
115 : mailbox_name1_(MailboxFromChar('1')),
116 mailbox_name2_(MailboxFromChar('2')),
117 sync_point1_(1),
118 sync_point2_(2),
119 shared_memory_(new base::SharedMemory) {
120 release_mailbox1_ = base::Bind(&MockMailboxCallback::Release,
121 base::Unretained(&mock_callback_),
122 mailbox_name1_);
123 release_mailbox2_ = base::Bind(&MockMailboxCallback::Release,
124 base::Unretained(&mock_callback_),
125 mailbox_name2_);
126 const uint32 arbitrary_target1 = GL_TEXTURE_2D;
127 const uint32 arbitrary_target2 = GL_TEXTURE_EXTERNAL_OES;
128 mailbox1_ = TextureMailbox(mailbox_name1_, arbitrary_target1, sync_point1_);
129 mailbox2_ = TextureMailbox(mailbox_name2_, arbitrary_target2, sync_point2_);
130 gfx::Size size(128, 128);
131 EXPECT_TRUE(shared_memory_->CreateAndMapAnonymous(4 * size.GetArea()));
132 release_mailbox3_ = base::Bind(&MockMailboxCallback::Release2,
133 base::Unretained(&mock_callback_),
134 shared_memory_.get());
135 mailbox3_ = TextureMailbox(shared_memory_.get(), size);
136 }
137
138 gpu::Mailbox mailbox_name1_;
139 gpu::Mailbox mailbox_name2_;
140 MockMailboxCallback mock_callback_;
141 ReleaseCallback release_mailbox1_;
142 ReleaseCallback release_mailbox2_;
143 ReleaseCallback release_mailbox3_;
144 TextureMailbox mailbox1_;
145 TextureMailbox mailbox2_;
146 TextureMailbox mailbox3_;
147 uint32 sync_point1_;
148 uint32 sync_point2_;
149 scoped_ptr<base::SharedMemory> shared_memory_;
150 };
151
152 class TextureLayerTest : public testing::Test { 64 class TextureLayerTest : public testing::Test {
153 public: 65 public:
154 TextureLayerTest() 66 TextureLayerTest()
155 : fake_client_( 67 : fake_client_(
156 FakeLayerTreeHostClient(FakeLayerTreeHostClient::DIRECT_3D)), 68 FakeLayerTreeHostClient(FakeLayerTreeHostClient::DIRECT_3D)),
157 host_impl_(&proxy_, &shared_bitmap_manager_) {} 69 host_impl_(&proxy_, &shared_bitmap_manager_) {}
158 70
159 protected: 71 protected:
160 virtual void SetUp() { 72 virtual void SetUp() {
161 layer_tree_host_.reset(new MockLayerTreeHost(&fake_client_)); 73 layer_tree_host_.reset(new MockLayerTreeHost(&fake_client_));
162 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
163 layer_tree_host_->SetViewportSize(gfx::Size(10, 10));
164 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
165 } 74 }
166 75
167 virtual void TearDown() { 76 virtual void TearDown() {
168 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 77 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
169 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber()); 78 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber());
170 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); 79 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
171 80
172 layer_tree_host_->SetRootLayer(NULL); 81 layer_tree_host_->SetRootLayer(NULL);
173 layer_tree_host_.reset(); 82 layer_tree_host_.reset();
174 } 83 }
175 84
176 scoped_ptr<MockLayerTreeHost> layer_tree_host_; 85 scoped_ptr<MockLayerTreeHost> layer_tree_host_;
177 FakeImplProxy proxy_; 86 FakeImplProxy proxy_;
178 FakeLayerTreeHostClient fake_client_; 87 FakeLayerTreeHostClient fake_client_;
179 TestSharedBitmapManager shared_bitmap_manager_; 88 TestSharedBitmapManager shared_bitmap_manager_;
180 FakeLayerTreeHostImpl host_impl_; 89 FakeLayerTreeHostImpl host_impl_;
181 }; 90 };
182 91
183 TEST_F(TextureLayerTest, SyncImplWhenClearingTexture) { 92 TEST_F(TextureLayerTest, SyncImplWhenChangingTextureId) {
184 scoped_ptr<TestWebGraphicsContext3D> context( 93 scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(NULL);
185 TestWebGraphicsContext3D::Create());
186 FakeTextureLayerClient client;
187 scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(&client);
188 ASSERT_TRUE(test_layer.get()); 94 ASSERT_TRUE(test_layer.get());
189 test_layer->SetIsDrawable(true);
190 test_layer->SetBounds(gfx::Size(10, 10));
191 95
192 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); 96 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber());
193 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); 97 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
194 layer_tree_host_->SetRootLayer(test_layer); 98 layer_tree_host_->SetRootLayer(test_layer);
195 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 99 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
196 EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get()); 100 EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get());
197 101
198 // Clearing the texture before we gave one should not sync.
199 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); 102 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
200 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0); 103 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
201 test_layer->ClearTexture(); 104 test_layer->SetTextureId(1);
202 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 105 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
203 106
204 // Give a texture to the layer through the client.
205 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
206 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(AtLeast(1));
207 client.set_texture(context->createTexture());
208 test_layer->SetNeedsDisplay();
209 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
210 // Force a commit.
211 layer_tree_host_->Composite(base::TimeTicks());
212
213 // Clearing the texture should sync.
214 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AtLeast(1)); 107 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AtLeast(1));
215 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); 108 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
216 test_layer->ClearTexture(); 109 test_layer->SetTextureId(2);
217 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 110 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
218 111
219 // But only once. 112 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AtLeast(1));
220 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
221 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0);
222 test_layer->ClearTexture();
223 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
224
225 // Force a commit to give another texture.
226 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(AtLeast(1));
227 test_layer->SetNeedsDisplay();
228 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
229 layer_tree_host_->Composite(base::TimeTicks());
230
231 // Make undrawable and commit.
232 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); 113 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
233 test_layer->SetIsDrawable(false); 114 test_layer->SetTextureId(0);
234 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
235 layer_tree_host_->Composite(base::TimeTicks());
236
237 // Clearing textures should not sync.
238 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
239 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
240 test_layer->ClearTexture();
241 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 115 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
242 } 116 }
243 117
244 TEST_F(TextureLayerTest, SyncImplWhenClearingMailbox) { 118 TEST_F(TextureLayerTest, SyncImplWhenDrawing) {
245 CommonMailboxObjects mailboxes; 119 gfx::RectF dirty_rect(0.f, 0.f, 1.f, 1.f);
246 FakeTextureLayerClient client; 120
247 scoped_refptr<TextureLayer> test_layer = 121 scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(NULL);
248 TextureLayer::CreateForMailbox(&client);
249 ASSERT_TRUE(test_layer.get()); 122 ASSERT_TRUE(test_layer.get());
250 test_layer->SetIsDrawable(true); 123 scoped_ptr<TextureLayerImpl> impl_layer;
251 test_layer->SetBounds(gfx::Size(10, 10)); 124 impl_layer = TextureLayerImpl::Create(host_impl_.active_tree(), 1, false);
252 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); 125 ASSERT_TRUE(impl_layer);
126
127 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber());
253 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); 128 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
254 layer_tree_host_->SetRootLayer(test_layer); 129 layer_tree_host_->SetRootLayer(test_layer);
130 test_layer->SetTextureId(1);
131 test_layer->SetIsDrawable(true);
255 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 132 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
256 EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get()); 133 EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get());
257 134
258 // Clearing the mailbox before we gave one should not sync. 135 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(1);
259 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); 136 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0);
260 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); 137 test_layer->WillModifyTexture();
261 test_layer->ClearTexture();
262 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 138 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
263 139
264 // Give a mailbox to the layer through the client.
265 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); 140 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
266 client.set_mailbox( 141 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(1);
267 mailboxes.mailbox1_, 142 test_layer->SetNeedsDisplayRect(dirty_rect);
268 SingleReleaseCallback::Create(mailboxes.release_mailbox1_));
269 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(AtLeast(1));
270 test_layer->SetNeedsDisplay();
271 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
272 // Force a commit.
273 layer_tree_host_->Composite(base::TimeTicks());
274
275 // Clearing the mailbox should not sync.
276 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
277 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
278 test_layer->ClearTexture();
279 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 143 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
280 144
281 // Commit will return mailbox1. 145 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
282 EXPECT_CALL(mailboxes.mock_callback_, 146 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1);
283 Release(mailboxes.mailbox_name1_, _, false)); 147 test_layer->PushPropertiesTo(impl_layer.get()); // fake commit
284 layer_tree_host_->Composite(base::TimeTicks()); 148 test_layer->SetIsDrawable(false);
285 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 149 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
286 150
287 // Force a commit to give another mailbox. 151 // Verify that non-drawable layers don't signal the compositor,
288 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); 152 // except for the first draw after last commit, which must acquire
289 client.set_mailbox( 153 // the texture.
290 mailboxes.mailbox2_, 154 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(1);
291 SingleReleaseCallback::Create(mailboxes.release_mailbox2_)); 155 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0);
292 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(AtLeast(1)); 156 test_layer->WillModifyTexture();
293 test_layer->SetNeedsDisplay(); 157 test_layer->SetNeedsDisplayRect(dirty_rect);
294 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 158 test_layer->PushPropertiesTo(impl_layer.get()); // fake commit
295 layer_tree_host_->Composite(base::TimeTicks());
296
297 // Make undrawable and commit.
298 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
299 test_layer->SetIsDrawable(false);
300 layer_tree_host_->Composite(base::TimeTicks());
301 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 159 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
302 160
303 // Clearing textures should not sync. 161 // Second draw with layer in non-drawable state: no texture
162 // acquisition.
304 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); 163 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
305 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); 164 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(0);
306 test_layer->ClearTexture(); 165 test_layer->WillModifyTexture();
307 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 166 test_layer->SetNeedsDisplayRect(dirty_rect);
308
309 // Commit will return the mailbox.
310 EXPECT_CALL(mailboxes.mock_callback_,
311 Release(mailboxes.mailbox_name2_, _, false));
312 layer_tree_host_->Composite(base::TimeTicks());
313 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 167 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
314 } 168 }
315 169
316 TEST_F(TextureLayerTest, SyncImplWhenRemovingFromTree) { 170 TEST_F(TextureLayerTest, SyncImplWhenRemovingFromTree) {
317 scoped_ptr<TestWebGraphicsContext3D> context(
318 TestWebGraphicsContext3D::Create());
319 scoped_refptr<Layer> root_layer = Layer::Create(); 171 scoped_refptr<Layer> root_layer = Layer::Create();
320 ASSERT_TRUE(root_layer.get()); 172 ASSERT_TRUE(root_layer.get());
321 scoped_refptr<Layer> child_layer = Layer::Create(); 173 scoped_refptr<Layer> child_layer = Layer::Create();
322 ASSERT_TRUE(child_layer.get()); 174 ASSERT_TRUE(child_layer.get());
323 root_layer->AddChild(child_layer); 175 root_layer->AddChild(child_layer);
324 FakeTextureLayerClient client; 176 scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(NULL);
325 scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(&client);
326 test_layer->SetIsDrawable(true);
327 test_layer->SetBounds(gfx::Size(10, 10));
328 ASSERT_TRUE(test_layer.get()); 177 ASSERT_TRUE(test_layer.get());
178 test_layer->SetTextureId(0);
329 child_layer->AddChild(test_layer); 179 child_layer->AddChild(test_layer);
330 180
331 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); 181 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber());
332 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); 182 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
333 layer_tree_host_->SetRootLayer(root_layer); 183 layer_tree_host_->SetRootLayer(root_layer);
334 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 184 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
335 185
336 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); 186 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
337 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); 187 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
338 test_layer->RemoveFromParent(); 188 test_layer->RemoveFromParent();
339 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 189 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
340 190
341 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); 191 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
342 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); 192 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
343 child_layer->AddChild(test_layer); 193 child_layer->AddChild(test_layer);
344 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 194 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
345 195
346 // Give a texture to the layer through the client.
347 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0); 196 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(0);
348 EXPECT_CALL(*layer_tree_host_, SetNeedsUpdateLayers()).Times(AtLeast(1)); 197 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
349 client.set_texture(context->createTexture()); 198 test_layer->SetTextureId(1);
350 test_layer->SetNeedsDisplay();
351 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 199 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
352 // Force a commit.
353 layer_tree_host_->Composite(base::TimeTicks());
354 200
355 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AtLeast(1)); 201 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AtLeast(1));
356 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); 202 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1));
357 test_layer->RemoveFromParent(); 203 test_layer->RemoveFromParent();
358 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 204 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
359 } 205 }
360 206
361 TEST_F(TextureLayerTest, CheckPropertyChangeCausesCorrectBehavior) { 207 TEST_F(TextureLayerTest, CheckPropertyChangeCausesCorrectBehavior) {
362 scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(NULL); 208 scoped_refptr<TextureLayer> test_layer = TextureLayer::Create(NULL);
363 EXPECT_SET_NEEDS_COMMIT(1, layer_tree_host_->SetRootLayer(test_layer)); 209 EXPECT_SET_NEEDS_COMMIT(1, layer_tree_host_->SetRootLayer(test_layer));
364 210
365 // Test properties that should call SetNeedsCommit. All properties need to 211 // Test properties that should call SetNeedsCommit. All properties need to
366 // be set to new values in order for SetNeedsCommit to be called. 212 // be set to new values in order for SetNeedsCommit to be called.
367 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetFlipped(false)); 213 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetFlipped(false));
368 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetUV( 214 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetUV(
369 gfx::PointF(0.25f, 0.25f), gfx::PointF(0.75f, 0.75f))); 215 gfx::PointF(0.25f, 0.25f), gfx::PointF(0.75f, 0.75f)));
370 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetVertexOpacity( 216 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetVertexOpacity(
371 0.5f, 0.5f, 0.5f, 0.5f)); 217 0.5f, 0.5f, 0.5f, 0.5f));
372 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetPremultipliedAlpha(false)); 218 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetPremultipliedAlpha(false));
373 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBlendBackgroundColor(true)); 219 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetBlendBackgroundColor(true));
220 EXPECT_SET_NEEDS_COMMIT(1, test_layer->SetTextureId(1));
221
222 // Calling SetTextureId can call AcquireLayerTextures.
223 EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber());
374 } 224 }
375 225
376 TEST_F(TextureLayerTest, VisibleContentOpaqueRegion) { 226 TEST_F(TextureLayerTest, VisibleContentOpaqueRegion) {
377 const gfx::Size layer_bounds(100, 100); 227 const gfx::Size layer_bounds(100, 100);
378 const gfx::Rect layer_rect(layer_bounds); 228 const gfx::Rect layer_rect(layer_bounds);
379 const Region layer_region(layer_rect); 229 const Region layer_region(layer_rect);
380 230
381 scoped_refptr<TextureLayer> layer = TextureLayer::Create(NULL); 231 scoped_refptr<TextureLayer> layer = TextureLayer::Create(NULL);
382 layer->SetBounds(layer_bounds); 232 layer->SetBounds(layer_bounds);
383 layer->draw_properties().visible_content_rect = layer_rect; 233 layer->draw_properties().visible_content_rect = layer_rect;
384 layer->SetBlendBackgroundColor(true); 234 layer->SetBlendBackgroundColor(true);
385 235
386 // Verify initial conditions. 236 // Verify initial conditions.
387 EXPECT_FALSE(layer->contents_opaque()); 237 EXPECT_FALSE(layer->contents_opaque());
388 EXPECT_EQ(0u, layer->background_color()); 238 EXPECT_EQ(0u, layer->background_color());
389 EXPECT_EQ(Region().ToString(), 239 EXPECT_EQ(Region().ToString(),
390 layer->VisibleContentOpaqueRegion().ToString()); 240 layer->VisibleContentOpaqueRegion().ToString());
391 241
392 // Opaque background. 242 // Opaque background.
393 layer->SetBackgroundColor(SK_ColorWHITE); 243 layer->SetBackgroundColor(SK_ColorWHITE);
394 EXPECT_EQ(layer_region.ToString(), 244 EXPECT_EQ(layer_region.ToString(),
395 layer->VisibleContentOpaqueRegion().ToString()); 245 layer->VisibleContentOpaqueRegion().ToString());
396 246
397 // Transparent background. 247 // Transparent background.
398 layer->SetBackgroundColor(SkColorSetARGB(100, 255, 255, 255)); 248 layer->SetBackgroundColor(SkColorSetARGB(100, 255, 255, 255));
399 EXPECT_EQ(Region().ToString(), 249 EXPECT_EQ(Region().ToString(),
400 layer->VisibleContentOpaqueRegion().ToString()); 250 layer->VisibleContentOpaqueRegion().ToString());
401 } 251 }
402 252
253 class FakeTextureLayerClient : public TextureLayerClient {
254 public:
255 FakeTextureLayerClient() {}
256
257 virtual unsigned PrepareTexture() OVERRIDE {
258 return 0;
259 }
260
261 virtual bool PrepareTextureMailbox(
262 TextureMailbox* mailbox,
263 scoped_ptr<SingleReleaseCallback>* release_callback,
264 bool use_shared_memory) OVERRIDE {
265 *mailbox = TextureMailbox();
266 *release_callback = scoped_ptr<SingleReleaseCallback>();
267 return true;
268 }
269
270 private:
271 DISALLOW_COPY_AND_ASSIGN(FakeTextureLayerClient);
272 };
273
403 TEST_F(TextureLayerTest, RateLimiter) { 274 TEST_F(TextureLayerTest, RateLimiter) {
404 FakeTextureLayerClient client; 275 FakeTextureLayerClient client;
405 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox( 276 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(
406 &client); 277 &client);
407 test_layer->SetIsDrawable(true); 278 test_layer->SetIsDrawable(true);
408 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); 279 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
409 layer_tree_host_->SetRootLayer(test_layer); 280 layer_tree_host_->SetRootLayer(test_layer);
410 281
411 // Don't rate limit until we invalidate. 282 // Don't rate limit until we invalidate.
412 EXPECT_CALL(*layer_tree_host_, StartRateLimiter()).Times(0); 283 EXPECT_CALL(*layer_tree_host_, StartRateLimiter()).Times(0);
(...skipping 25 matching lines...) Expand all
438 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber()); 309 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AnyNumber());
439 layer_tree_host_->SetRootLayer(test_layer); 310 layer_tree_host_->SetRootLayer(test_layer);
440 EXPECT_CALL(*layer_tree_host_, StartRateLimiter()).Times(0); 311 EXPECT_CALL(*layer_tree_host_, StartRateLimiter()).Times(0);
441 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 312 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
442 EXPECT_CALL(*layer_tree_host_, StartRateLimiter()); 313 EXPECT_CALL(*layer_tree_host_, StartRateLimiter());
443 test_layer->SetNeedsDisplay(); 314 test_layer->SetNeedsDisplay();
444 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 315 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
445 316
446 // Stop rate limiter when we're removed from the tree. 317 // Stop rate limiter when we're removed from the tree.
447 EXPECT_CALL(*layer_tree_host_, StopRateLimiter()); 318 EXPECT_CALL(*layer_tree_host_, StopRateLimiter());
448 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(1);
449 layer_tree_host_->SetRootLayer(NULL); 319 layer_tree_host_->SetRootLayer(NULL);
450 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 320 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
451 } 321 }
452 322
323 class MockMailboxCallback {
324 public:
325 MOCK_METHOD3(Release,
326 void(const gpu::Mailbox& mailbox,
327 uint32 sync_point,
328 bool lost_resource));
329 MOCK_METHOD3(Release2,
330 void(base::SharedMemory* shared_memory,
331 uint32 sync_point,
332 bool lost_resource));
333 };
334
335 struct CommonMailboxObjects {
336 CommonMailboxObjects()
337 : mailbox_name1_(MailboxFromChar('1')),
338 mailbox_name2_(MailboxFromChar('2')),
339 sync_point1_(1),
340 sync_point2_(2),
341 shared_memory_(new base::SharedMemory) {
342 release_mailbox1_ = base::Bind(&MockMailboxCallback::Release,
343 base::Unretained(&mock_callback_),
344 mailbox_name1_);
345 release_mailbox2_ = base::Bind(&MockMailboxCallback::Release,
346 base::Unretained(&mock_callback_),
347 mailbox_name2_);
348 const uint32 arbitrary_target1 = 1;
349 const uint32 arbitrary_target2 = 2;
350 mailbox1_ = TextureMailbox(mailbox_name1_, arbitrary_target1, sync_point1_);
351 mailbox2_ = TextureMailbox(mailbox_name2_, arbitrary_target2, sync_point2_);
352 gfx::Size size(128, 128);
353 EXPECT_TRUE(shared_memory_->CreateAndMapAnonymous(4 * size.GetArea()));
354 release_mailbox3_ = base::Bind(&MockMailboxCallback::Release2,
355 base::Unretained(&mock_callback_),
356 shared_memory_.get());
357 mailbox3_ = TextureMailbox(shared_memory_.get(), size);
358 }
359
360 gpu::Mailbox mailbox_name1_;
361 gpu::Mailbox mailbox_name2_;
362 MockMailboxCallback mock_callback_;
363 ReleaseCallback release_mailbox1_;
364 ReleaseCallback release_mailbox2_;
365 ReleaseCallback release_mailbox3_;
366 TextureMailbox mailbox1_;
367 TextureMailbox mailbox2_;
368 TextureMailbox mailbox3_;
369 uint32 sync_point1_;
370 uint32 sync_point2_;
371 scoped_ptr<base::SharedMemory> shared_memory_;
372 };
373
453 class TestMailboxHolder : public TextureLayer::TextureMailboxHolder { 374 class TestMailboxHolder : public TextureLayer::TextureMailboxHolder {
454 public: 375 public:
455 using TextureLayer::TextureMailboxHolder::Create; 376 using TextureLayer::TextureMailboxHolder::Create;
456 377
457 protected: 378 protected:
458 virtual ~TestMailboxHolder() {} 379 virtual ~TestMailboxHolder() {}
459 }; 380 };
460 381
461 class TextureLayerWithMailboxTest : public TextureLayerTest { 382 class TextureLayerWithMailboxTest : public TextureLayerTest {
462 protected: 383 protected:
(...skipping 1808 matching lines...) Expand 10 before | Expand all | Expand 10 after
2271 int callback_count_; 2192 int callback_count_;
2272 scoped_refptr<Layer> root_; 2193 scoped_refptr<Layer> root_;
2273 scoped_refptr<TextureLayer> layer_; 2194 scoped_refptr<TextureLayer> layer_;
2274 }; 2195 };
2275 2196
2276 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( 2197 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(
2277 TextureLayerWithMailboxImplThreadDeleted); 2198 TextureLayerWithMailboxImplThreadDeleted);
2278 2199
2279 } // namespace 2200 } // namespace
2280 } // namespace cc 2201 } // namespace cc
OLDNEW
« no previous file with comments | « trunk/src/cc/layers/texture_layer.cc ('k') | trunk/src/content/shell/renderer/test_runner/TestPlugin.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698