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

Side by Side Diff: gpu/command_buffer/service/mailbox_manager_unittest.cc

Issue 681713002: Update from chromium https://crrev.com/301315 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "gpu/command_buffer/service/mailbox_manager.h"
6
7 #include "gpu/command_buffer/service/feature_info.h" 5 #include "gpu/command_buffer/service/feature_info.h"
8 #include "gpu/command_buffer/service/gpu_service_test.h" 6 #include "gpu/command_buffer/service/gpu_service_test.h"
9 #include "gpu/command_buffer/service/mailbox_synchronizer.h" 7 #include "gpu/command_buffer/service/mailbox_manager_impl.h"
8 #include "gpu/command_buffer/service/mailbox_manager_sync.h"
10 #include "gpu/command_buffer/service/texture_manager.h" 9 #include "gpu/command_buffer/service/texture_manager.h"
11 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/gl/gl_context_stub.h" 11 #include "ui/gl/gl_context_stub.h"
13 #include "ui/gl/gl_mock.h" 12 #include "ui/gl/gl_mock.h"
14 #include "ui/gl/gl_surface_stub.h" 13 #include "ui/gl/gl_surface_stub.h"
15 14
16 namespace gpu { 15 namespace gpu {
17 namespace gles2 { 16 namespace gles2 {
18 17
19 using namespace ::testing; 18 using namespace ::testing;
20 19
21 class MailboxManagerTest : public GpuServiceTest { 20 class MailboxManagerTest : public GpuServiceTest {
22 public: 21 public:
23 MailboxManagerTest() : initialized_synchronizer_(false) {} 22 MailboxManagerTest() {}
24 virtual ~MailboxManagerTest() {} 23 virtual ~MailboxManagerTest() {}
25 24
26 protected: 25 protected:
27 virtual void SetUp() { 26 virtual void SetUp() {
28 GpuServiceTest::SetUp(); 27 GpuServiceTest::SetUp();
29 feature_info_ = new FeatureInfo; 28 feature_info_ = new FeatureInfo;
30 manager_ = new MailboxManager; 29 manager_ = new MailboxManagerImpl;
30 DCHECK(!manager_->UsesSync());
31 } 31 }
32 32
33 virtual void SetUpWithSynchronizer() { 33 virtual void SetUpWithSynchronizer() {
34 GpuServiceTest::SetUp(); 34 GpuServiceTest::SetUp();
35 MailboxSynchronizer::Initialize();
36 initialized_synchronizer_ = true;
37 feature_info_ = new FeatureInfo; 35 feature_info_ = new FeatureInfo;
38 manager_ = new MailboxManager; 36 manager_ = new MailboxManagerSync();
37 DCHECK(manager_->UsesSync());
39 } 38 }
40 39
41 virtual void TearDown() { 40 virtual void TearDown() {
42 if (initialized_synchronizer_)
43 MailboxSynchronizer::Terminate();
44 GpuServiceTest::TearDown(); 41 GpuServiceTest::TearDown();
45 } 42 }
46 43
47 Texture* CreateTexture() { 44 Texture* CreateTexture() {
48 return new Texture(1); 45 return new Texture(1);
49 } 46 }
50 47
51 void SetTarget(Texture* texture, GLenum target, GLuint max_level) { 48 void SetTarget(Texture* texture, GLenum target, GLuint max_level) {
52 texture->SetTarget(NULL, target, max_level); 49 texture->SetTarget(NULL, target, max_level);
53 } 50 }
(...skipping 27 matching lines...) Expand all
81 return texture->SetParameteri(feature_info_.get(), pname, param); 78 return texture->SetParameteri(feature_info_.get(), pname, param);
82 } 79 }
83 80
84 void DestroyTexture(Texture* texture) { 81 void DestroyTexture(Texture* texture) {
85 delete texture; 82 delete texture;
86 } 83 }
87 84
88 scoped_refptr<MailboxManager> manager_; 85 scoped_refptr<MailboxManager> manager_;
89 86
90 private: 87 private:
91 bool initialized_synchronizer_;
92 scoped_refptr<FeatureInfo> feature_info_; 88 scoped_refptr<FeatureInfo> feature_info_;
93 89
94 DISALLOW_COPY_AND_ASSIGN(MailboxManagerTest); 90 DISALLOW_COPY_AND_ASSIGN(MailboxManagerTest);
95 }; 91 };
96 92
97 // Tests basic produce/consume behavior. 93 // Tests basic produce/consume behavior.
98 TEST_F(MailboxManagerTest, Basic) { 94 TEST_F(MailboxManagerTest, Basic) {
99 Texture* texture = CreateTexture(); 95 Texture* texture = CreateTexture();
100 96
101 Mailbox name = Mailbox::Generate(); 97 Mailbox name = Mailbox::Generate();
102 manager_->ProduceTexture(0, name, texture); 98 manager_->ProduceTexture(name, texture);
103 EXPECT_EQ(texture, manager_->ConsumeTexture(0, name)); 99 EXPECT_EQ(texture, manager_->ConsumeTexture(name));
104 100
105 // We can consume multiple times. 101 // We can consume multiple times.
106 EXPECT_EQ(texture, manager_->ConsumeTexture(0, name)); 102 EXPECT_EQ(texture, manager_->ConsumeTexture(name));
107
108 // Wrong target should fail the consume.
109 EXPECT_EQ(NULL, manager_->ConsumeTexture(1, name));
110 103
111 // Destroy should cleanup the mailbox. 104 // Destroy should cleanup the mailbox.
112 DestroyTexture(texture); 105 DestroyTexture(texture);
113 EXPECT_EQ(NULL, manager_->ConsumeTexture(0, name)); 106 EXPECT_EQ(NULL, manager_->ConsumeTexture(name));
114 } 107 }
115 108
116 // Tests behavior with multiple produce on the same texture. 109 // Tests behavior with multiple produce on the same texture.
117 TEST_F(MailboxManagerTest, ProduceMultipleMailbox) { 110 TEST_F(MailboxManagerTest, ProduceMultipleMailbox) {
118 Texture* texture = CreateTexture(); 111 Texture* texture = CreateTexture();
119 112
120 Mailbox name1 = Mailbox::Generate(); 113 Mailbox name1 = Mailbox::Generate();
121 114
122 manager_->ProduceTexture(0, name1, texture); 115 manager_->ProduceTexture(name1, texture);
123 EXPECT_EQ(texture, manager_->ConsumeTexture(0, name1)); 116 EXPECT_EQ(texture, manager_->ConsumeTexture(name1));
124 117
125 // Can produce a second time with the same mailbox. 118 // Can produce a second time with the same mailbox.
126 manager_->ProduceTexture(0, name1, texture); 119 manager_->ProduceTexture(name1, texture);
127 EXPECT_EQ(texture, manager_->ConsumeTexture(0, name1)); 120 EXPECT_EQ(texture, manager_->ConsumeTexture(name1));
128 121
129 // Can produce again, with a different mailbox. 122 // Can produce again, with a different mailbox.
130 Mailbox name2 = Mailbox::Generate(); 123 Mailbox name2 = Mailbox::Generate();
131 manager_->ProduceTexture(0, name2, texture); 124 manager_->ProduceTexture(name2, texture);
132 125
133 // Still available under all mailboxes. 126 // Still available under all mailboxes.
134 EXPECT_EQ(texture, manager_->ConsumeTexture(0, name1)); 127 EXPECT_EQ(texture, manager_->ConsumeTexture(name1));
135 EXPECT_EQ(texture, manager_->ConsumeTexture(0, name2)); 128 EXPECT_EQ(texture, manager_->ConsumeTexture(name2));
136 129
137 // Destroy should cleanup all mailboxes. 130 // Destroy should cleanup all mailboxes.
138 DestroyTexture(texture); 131 DestroyTexture(texture);
139 EXPECT_EQ(NULL, manager_->ConsumeTexture(0, name1)); 132 EXPECT_EQ(NULL, manager_->ConsumeTexture(name1));
140 EXPECT_EQ(NULL, manager_->ConsumeTexture(0, name2)); 133 EXPECT_EQ(NULL, manager_->ConsumeTexture(name2));
141 } 134 }
142 135
143 // Tests behavior with multiple produce on the same mailbox with different 136 // Tests behavior with multiple produce on the same mailbox with different
144 // textures. 137 // textures.
145 TEST_F(MailboxManagerTest, ProduceMultipleTexture) { 138 TEST_F(MailboxManagerTest, ProduceMultipleTexture) {
146 Texture* texture1 = CreateTexture(); 139 Texture* texture1 = CreateTexture();
147 Texture* texture2 = CreateTexture(); 140 Texture* texture2 = CreateTexture();
148 141
149 Mailbox name = Mailbox::Generate(); 142 Mailbox name = Mailbox::Generate();
150 143
151 manager_->ProduceTexture(0, name, texture1); 144 manager_->ProduceTexture(name, texture1);
152 EXPECT_EQ(texture1, manager_->ConsumeTexture(0, name)); 145 EXPECT_EQ(texture1, manager_->ConsumeTexture(name));
153 146
154 // Can produce a second time with the same mailbox, but different texture. 147 // Can produce a second time with the same mailbox, but different texture.
155 manager_->ProduceTexture(0, name, texture2); 148 manager_->ProduceTexture(name, texture2);
156 EXPECT_EQ(texture2, manager_->ConsumeTexture(0, name)); 149 EXPECT_EQ(texture2, manager_->ConsumeTexture(name));
157 150
158 // Destroying the texture that's under no mailbox shouldn't have an effect. 151 // Destroying the texture that's under no mailbox shouldn't have an effect.
159 DestroyTexture(texture1); 152 DestroyTexture(texture1);
160 EXPECT_EQ(texture2, manager_->ConsumeTexture(0, name)); 153 EXPECT_EQ(texture2, manager_->ConsumeTexture(name));
161 154
162 // Destroying the texture that's bound should clean up. 155 // Destroying the texture that's bound should clean up.
163 DestroyTexture(texture2); 156 DestroyTexture(texture2);
164 EXPECT_EQ(NULL, manager_->ConsumeTexture(0, name)); 157 EXPECT_EQ(NULL, manager_->ConsumeTexture(name));
165 } 158 }
166 159
167 TEST_F(MailboxManagerTest, ProduceMultipleTextureMailbox) { 160 TEST_F(MailboxManagerTest, ProduceMultipleTextureMailbox) {
168 Texture* texture1 = CreateTexture(); 161 Texture* texture1 = CreateTexture();
169 Texture* texture2 = CreateTexture(); 162 Texture* texture2 = CreateTexture();
170 Mailbox name1 = Mailbox::Generate(); 163 Mailbox name1 = Mailbox::Generate();
171 Mailbox name2 = Mailbox::Generate(); 164 Mailbox name2 = Mailbox::Generate();
172 165
173 // Put texture1 on name1 and name2. 166 // Put texture1 on name1 and name2.
174 manager_->ProduceTexture(0, name1, texture1); 167 manager_->ProduceTexture(name1, texture1);
175 manager_->ProduceTexture(0, name2, texture1); 168 manager_->ProduceTexture(name2, texture1);
176 EXPECT_EQ(texture1, manager_->ConsumeTexture(0, name1)); 169 EXPECT_EQ(texture1, manager_->ConsumeTexture(name1));
177 EXPECT_EQ(texture1, manager_->ConsumeTexture(0, name2)); 170 EXPECT_EQ(texture1, manager_->ConsumeTexture(name2));
178 171
179 // Put texture2 on name2. 172 // Put texture2 on name2.
180 manager_->ProduceTexture(0, name2, texture2); 173 manager_->ProduceTexture(name2, texture2);
181 EXPECT_EQ(texture1, manager_->ConsumeTexture(0, name1)); 174 EXPECT_EQ(texture1, manager_->ConsumeTexture(name1));
182 EXPECT_EQ(texture2, manager_->ConsumeTexture(0, name2)); 175 EXPECT_EQ(texture2, manager_->ConsumeTexture(name2));
183 176
184 // Destroy texture1, shouldn't affect name2. 177 // Destroy texture1, shouldn't affect name2.
185 DestroyTexture(texture1); 178 DestroyTexture(texture1);
186 EXPECT_EQ(NULL, manager_->ConsumeTexture(0, name1)); 179 EXPECT_EQ(NULL, manager_->ConsumeTexture(name1));
187 EXPECT_EQ(texture2, manager_->ConsumeTexture(0, name2)); 180 EXPECT_EQ(texture2, manager_->ConsumeTexture(name2));
188 181
189 DestroyTexture(texture2); 182 DestroyTexture(texture2);
190 EXPECT_EQ(NULL, manager_->ConsumeTexture(0, name2)); 183 EXPECT_EQ(NULL, manager_->ConsumeTexture(name2));
191 } 184 }
192 185
193 const GLsizei kMaxTextureWidth = 64; 186 const GLsizei kMaxTextureWidth = 64;
194 const GLsizei kMaxTextureHeight = 64; 187 const GLsizei kMaxTextureHeight = 64;
195 const GLsizei kMaxTextureDepth = 1; 188 const GLsizei kMaxTextureDepth = 1;
196 189
197 class MailboxManagerSyncTest : public MailboxManagerTest { 190 class MailboxManagerSyncTest : public MailboxManagerTest {
198 public: 191 public:
199 MailboxManagerSyncTest() {} 192 MailboxManagerSyncTest() {}
200 virtual ~MailboxManagerSyncTest() {} 193 virtual ~MailboxManagerSyncTest() {}
201 194
202 protected: 195 protected:
203 virtual void SetUp() { 196 virtual void SetUp() {
204 MailboxManagerTest::SetUpWithSynchronizer(); 197 MailboxManagerTest::SetUpWithSynchronizer();
205 manager2_ = new MailboxManager; 198 manager2_ = new MailboxManagerSync();
206 context_ = new gfx::GLContextStub(); 199 context_ = new gfx::GLContextStub();
207 surface_ = new gfx::GLSurfaceStub(); 200 surface_ = new gfx::GLSurfaceStub();
208 context_->MakeCurrent(surface_.get()); 201 context_->MakeCurrent(surface_.get());
209 } 202 }
210 203
211 Texture* DefineTexture() { 204 Texture* DefineTexture() {
212 Texture* texture = CreateTexture(); 205 Texture* texture = CreateTexture();
213 const GLsizei levels_needed = TextureManager::ComputeMipMapCount( 206 const GLsizei levels_needed = TextureManager::ComputeMipMapCount(
214 GL_TEXTURE_2D, kMaxTextureWidth, kMaxTextureHeight, kMaxTextureDepth); 207 GL_TEXTURE_2D, kMaxTextureWidth, kMaxTextureHeight, kMaxTextureDepth);
215 SetTarget(texture, GL_TEXTURE_2D, levels_needed); 208 SetTarget(texture, GL_TEXTURE_2D, levels_needed);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 268
276 private: 269 private:
277 DISALLOW_COPY_AND_ASSIGN(MailboxManagerSyncTest); 270 DISALLOW_COPY_AND_ASSIGN(MailboxManagerSyncTest);
278 }; 271 };
279 272
280 TEST_F(MailboxManagerSyncTest, ProduceDestroy) { 273 TEST_F(MailboxManagerSyncTest, ProduceDestroy) {
281 Texture* texture = DefineTexture(); 274 Texture* texture = DefineTexture();
282 Mailbox name = Mailbox::Generate(); 275 Mailbox name = Mailbox::Generate();
283 276
284 InSequence sequence; 277 InSequence sequence;
285 manager_->ProduceTexture(GL_TEXTURE_2D, name, texture); 278 manager_->ProduceTexture(name, texture);
286 EXPECT_EQ(texture, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); 279 EXPECT_EQ(texture, manager_->ConsumeTexture(name));
287 280
288 DestroyTexture(texture); 281 DestroyTexture(texture);
289 EXPECT_EQ(NULL, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); 282 EXPECT_EQ(NULL, manager_->ConsumeTexture(name));
290 EXPECT_EQ(NULL, manager2_->ConsumeTexture(GL_TEXTURE_2D, name)); 283 EXPECT_EQ(NULL, manager2_->ConsumeTexture(name));
291 } 284 }
292 285
293 TEST_F(MailboxManagerSyncTest, ProduceSyncDestroy) { 286 TEST_F(MailboxManagerSyncTest, ProduceSyncDestroy) {
294 InSequence sequence; 287 InSequence sequence;
295 288
296 Texture* texture = DefineTexture(); 289 Texture* texture = DefineTexture();
297 Mailbox name = Mailbox::Generate(); 290 Mailbox name = Mailbox::Generate();
298 291
299 manager_->ProduceTexture(GL_TEXTURE_2D, name, texture); 292 manager_->ProduceTexture(name, texture);
300 EXPECT_EQ(texture, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); 293 EXPECT_EQ(texture, manager_->ConsumeTexture(name));
301 294
302 // Synchronize 295 // Synchronize
303 manager_->PushTextureUpdates(0); 296 manager_->PushTextureUpdates(0);
304 manager2_->PullTextureUpdates(0); 297 manager2_->PullTextureUpdates(0);
305 298
306 DestroyTexture(texture); 299 DestroyTexture(texture);
307 EXPECT_EQ(NULL, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); 300 EXPECT_EQ(NULL, manager_->ConsumeTexture(name));
308 EXPECT_EQ(NULL, manager2_->ConsumeTexture(GL_TEXTURE_2D, name)); 301 EXPECT_EQ(NULL, manager2_->ConsumeTexture(name));
302 }
303
304 TEST_F(MailboxManagerSyncTest, ProduceSyncClobberDestroy) {
305 InSequence sequence;
306
307 Texture* texture = DefineTexture();
308 Mailbox name = Mailbox::Generate();
309
310 manager_->ProduceTexture(name, texture);
311 manager_->PushTextureUpdates(0);
312
313 // Clobber
314 Texture* old_texture = texture;
315 texture = DefineTexture();
316 manager_->ProduceTexture(name, texture);
317
318 DestroyTexture(old_texture);
319 DestroyTexture(texture);
320 EXPECT_EQ(NULL, manager_->ConsumeTexture(name));
321 EXPECT_EQ(NULL, manager2_->ConsumeTexture(name));
309 } 322 }
310 323
311 // Duplicates a texture into a second manager instance, and then 324 // Duplicates a texture into a second manager instance, and then
312 // makes sure a redefinition becomes visible there too. 325 // makes sure a redefinition becomes visible there too.
313 TEST_F(MailboxManagerSyncTest, ProduceConsumeResize) { 326 TEST_F(MailboxManagerSyncTest, ProduceConsumeResize) {
314 const GLuint kNewTextureId = 1234; 327 const GLuint kNewTextureId = 1234;
315 InSequence sequence; 328 InSequence sequence;
316 329
317 Texture* texture = DefineTexture(); 330 Texture* texture = DefineTexture();
318 Mailbox name = Mailbox::Generate(); 331 Mailbox name = Mailbox::Generate();
319 332
320 manager_->ProduceTexture(GL_TEXTURE_2D, name, texture); 333 manager_->ProduceTexture(name, texture);
321 EXPECT_EQ(texture, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); 334 EXPECT_EQ(texture, manager_->ConsumeTexture(name));
322 335
323 // Synchronize 336 // Synchronize
324 manager_->PushTextureUpdates(0); 337 manager_->PushTextureUpdates(0);
325 manager2_->PullTextureUpdates(0); 338 manager2_->PullTextureUpdates(0);
326 339
327 EXPECT_CALL(*gl_, GenTextures(1, _)) 340 EXPECT_CALL(*gl_, GenTextures(1, _))
328 .WillOnce(SetArgPointee<1>(kNewTextureId)); 341 .WillOnce(SetArgPointee<1>(kNewTextureId));
329 SetupUpdateTexParamExpectations( 342 SetupUpdateTexParamExpectations(
330 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); 343 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
331 Texture* new_texture = manager2_->ConsumeTexture(GL_TEXTURE_2D, name); 344 Texture* new_texture = manager2_->ConsumeTexture(name);
332 EXPECT_FALSE(new_texture == NULL); 345 EXPECT_FALSE(new_texture == NULL);
333 EXPECT_NE(texture, new_texture); 346 EXPECT_NE(texture, new_texture);
334 EXPECT_EQ(kNewTextureId, new_texture->service_id()); 347 EXPECT_EQ(kNewTextureId, new_texture->service_id());
335 348
336 // Resize original texture 349 // Resize original texture
337 SetLevelInfo(texture, 350 SetLevelInfo(texture,
338 GL_TEXTURE_2D, 351 GL_TEXTURE_2D,
339 0, 352 0,
340 GL_RGBA, 353 GL_RGBA,
341 16, 354 16,
(...skipping 29 matching lines...) Expand all
371 0, 384 0,
372 GL_RGBA, 385 GL_RGBA,
373 GL_UNSIGNED_BYTE, 386 GL_UNSIGNED_BYTE,
374 true); 387 true);
375 // ...and immediately delete the texture which should save the changes. 388 // ...and immediately delete the texture which should save the changes.
376 SetupUpdateTexParamExpectations( 389 SetupUpdateTexParamExpectations(
377 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); 390 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
378 DestroyTexture(texture); 391 DestroyTexture(texture);
379 392
380 // Should be still around since there is a ref from manager2 393 // Should be still around since there is a ref from manager2
381 EXPECT_EQ(new_texture, manager2_->ConsumeTexture(GL_TEXTURE_2D, name)); 394 EXPECT_EQ(new_texture, manager2_->ConsumeTexture(name));
382 395
383 // The last change to the texture should be visible without a sync point (i.e. 396 // The last change to the texture should be visible without a sync point (i.e.
384 // push). 397 // push).
385 manager2_->PullTextureUpdates(0); 398 manager2_->PullTextureUpdates(0);
386 new_texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height); 399 new_texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height);
387 EXPECT_EQ(64, width); 400 EXPECT_EQ(64, width);
388 EXPECT_EQ(64, height); 401 EXPECT_EQ(64, height);
389 402
390 DestroyTexture(new_texture); 403 DestroyTexture(new_texture);
391 EXPECT_EQ(NULL, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); 404 EXPECT_EQ(NULL, manager_->ConsumeTexture(name));
392 EXPECT_EQ(NULL, manager2_->ConsumeTexture(GL_TEXTURE_2D, name)); 405 EXPECT_EQ(NULL, manager2_->ConsumeTexture(name));
393 } 406 }
394 407
395 // Makes sure changes are correctly published even when updates are 408 // Makes sure changes are correctly published even when updates are
396 // pushed in both directions, i.e. makes sure we don't clobber a shared 409 // pushed in both directions, i.e. makes sure we don't clobber a shared
397 // texture definition with an older version. 410 // texture definition with an older version.
398 TEST_F(MailboxManagerSyncTest, ProduceConsumeBidirectional) { 411 TEST_F(MailboxManagerSyncTest, ProduceConsumeBidirectional) {
399 const GLuint kNewTextureId1 = 1234; 412 const GLuint kNewTextureId1 = 1234;
400 const GLuint kNewTextureId2 = 4321; 413 const GLuint kNewTextureId2 = 4321;
401 414
402 Texture* texture1 = DefineTexture(); 415 Texture* texture1 = DefineTexture();
403 Mailbox name1 = Mailbox::Generate(); 416 Mailbox name1 = Mailbox::Generate();
404 Texture* texture2 = DefineTexture(); 417 Texture* texture2 = DefineTexture();
405 Mailbox name2 = Mailbox::Generate(); 418 Mailbox name2 = Mailbox::Generate();
406 Texture* new_texture1 = NULL; 419 Texture* new_texture1 = NULL;
407 Texture* new_texture2 = NULL; 420 Texture* new_texture2 = NULL;
408 421
409 manager_->ProduceTexture(GL_TEXTURE_2D, name1, texture1); 422 manager_->ProduceTexture(name1, texture1);
410 manager2_->ProduceTexture(GL_TEXTURE_2D, name2, texture2); 423 manager2_->ProduceTexture(name2, texture2);
411 424
412 // Make visible. 425 // Make visible.
413 manager_->PushTextureUpdates(0); 426 manager_->PushTextureUpdates(0);
414 manager2_->PushTextureUpdates(0); 427 manager2_->PushTextureUpdates(0);
415 428
416 // Create textures in the other manager instances for texture1 and texture2, 429 // Create textures in the other manager instances for texture1 and texture2,
417 // respectively to create a real sharing scenario. Otherwise, there would 430 // respectively to create a real sharing scenario. Otherwise, there would
418 // never be conflicting updates/pushes. 431 // never be conflicting updates/pushes.
419 { 432 {
420 InSequence sequence; 433 InSequence sequence;
421 EXPECT_CALL(*gl_, GenTextures(1, _)) 434 EXPECT_CALL(*gl_, GenTextures(1, _))
422 .WillOnce(SetArgPointee<1>(kNewTextureId1)); 435 .WillOnce(SetArgPointee<1>(kNewTextureId1));
423 SetupUpdateTexParamExpectations( 436 SetupUpdateTexParamExpectations(
424 kNewTextureId1, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); 437 kNewTextureId1, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
425 new_texture1 = manager2_->ConsumeTexture(GL_TEXTURE_2D, name1); 438 new_texture1 = manager2_->ConsumeTexture(name1);
426 EXPECT_CALL(*gl_, GenTextures(1, _)) 439 EXPECT_CALL(*gl_, GenTextures(1, _))
427 .WillOnce(SetArgPointee<1>(kNewTextureId2)); 440 .WillOnce(SetArgPointee<1>(kNewTextureId2));
428 SetupUpdateTexParamExpectations( 441 SetupUpdateTexParamExpectations(
429 kNewTextureId2, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); 442 kNewTextureId2, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
430 new_texture2 = manager_->ConsumeTexture(GL_TEXTURE_2D, name2); 443 new_texture2 = manager_->ConsumeTexture(name2);
431 } 444 }
432 EXPECT_EQ(kNewTextureId1, new_texture1->service_id()); 445 EXPECT_EQ(kNewTextureId1, new_texture1->service_id());
433 EXPECT_EQ(kNewTextureId2, new_texture2->service_id()); 446 EXPECT_EQ(kNewTextureId2, new_texture2->service_id());
434 447
435 // Make a change to texture1 448 // Make a change to texture1
436 DCHECK_EQ(static_cast<GLuint>(GL_LINEAR), texture1->min_filter()); 449 DCHECK_EQ(static_cast<GLuint>(GL_LINEAR), texture1->min_filter());
437 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), 450 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR),
438 SetParameter(texture1, GL_TEXTURE_MIN_FILTER, GL_NEAREST)); 451 SetParameter(texture1, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
439 452
440 // Make sure this does not clobber it with the previous version we pushed. 453 // Make sure this does not clobber it with the previous version we pushed.
(...skipping 17 matching lines...) Expand all
458 SetupUpdateTexParamExpectations( 471 SetupUpdateTexParamExpectations(
459 new_texture1->service_id(), GL_NEAREST, GL_LINEAR, GL_REPEAT, GL_REPEAT); 472 new_texture1->service_id(), GL_NEAREST, GL_LINEAR, GL_REPEAT, GL_REPEAT);
460 manager2_->PullTextureUpdates(0); 473 manager2_->PullTextureUpdates(0);
461 474
462 DestroyTexture(texture1); 475 DestroyTexture(texture1);
463 DestroyTexture(texture2); 476 DestroyTexture(texture2);
464 DestroyTexture(new_texture1); 477 DestroyTexture(new_texture1);
465 DestroyTexture(new_texture2); 478 DestroyTexture(new_texture2);
466 } 479 }
467 480
468 // TODO: different texture into same mailbox 481 // If a texture is shared with another manager instance, but the mailbox
482 // is then clobbered with a different texture in the source context, this should
483 // disconnect the earlier texture from updates.
484 TEST_F(MailboxManagerSyncTest, ProduceAndClobber) {
485 const GLuint kNewTextureId = 1234;
486 InSequence sequence;
469 487
470 // TODO: same texture, multiple mailboxes 488 Texture* texture = DefineTexture();
489 Mailbox name = Mailbox::Generate();
490
491 manager_->ProduceTexture(name, texture);
492 EXPECT_EQ(texture, manager_->ConsumeTexture(name));
493
494 // Synchronize
495 manager_->PushTextureUpdates(0);
496 manager2_->PullTextureUpdates(0);
497
498 EXPECT_CALL(*gl_, GenTextures(1, _))
499 .WillOnce(SetArgPointee<1>(kNewTextureId));
500 SetupUpdateTexParamExpectations(
501 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
502 Texture* new_texture = manager2_->ConsumeTexture(name);
503 EXPECT_FALSE(new_texture == NULL);
504 EXPECT_NE(texture, new_texture);
505 EXPECT_EQ(kNewTextureId, new_texture->service_id());
506
507 Texture* old_texture = texture;
508 texture = DefineTexture();
509 manager_->ProduceTexture(name, texture);
510
511 // Make a change to the new texture
512 DCHECK_EQ(static_cast<GLuint>(GL_LINEAR), texture->min_filter());
513 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR),
514 SetParameter(texture, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
515
516 // Synchronize in both directions - no changes, since it's not shared
517 manager_->PushTextureUpdates(0);
518 manager2_->PullTextureUpdates(0);
519 EXPECT_EQ(static_cast<GLuint>(GL_LINEAR), new_texture->min_filter());
520
521 // Make a change to the previously shared texture
522 DCHECK_EQ(static_cast<GLuint>(GL_LINEAR), old_texture->mag_filter());
523 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR),
524 SetParameter(old_texture, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
525
526 // Synchronize and expect update
527 manager_->PushTextureUpdates(0);
528 SetupUpdateTexParamExpectations(
529 new_texture->service_id(), GL_LINEAR, GL_NEAREST, GL_REPEAT, GL_REPEAT);
530 manager2_->PullTextureUpdates(0);
531
532 EXPECT_CALL(*gl_, GenTextures(1, _))
533 .WillOnce(SetArgPointee<1>(kNewTextureId));
534 SetupUpdateTexParamExpectations(
535 kNewTextureId, GL_NEAREST, GL_LINEAR, GL_REPEAT, GL_REPEAT);
536 Texture* tmp_texture = manager2_->ConsumeTexture(name);
537 EXPECT_NE(new_texture, tmp_texture);
538 DestroyTexture(tmp_texture);
539
540 DestroyTexture(old_texture);
541 DestroyTexture(texture);
542 DestroyTexture(new_texture);
543
544 EXPECT_EQ(NULL, manager_->ConsumeTexture(name));
545 EXPECT_EQ(NULL, manager2_->ConsumeTexture(name));
546 }
547
548 // Putting the same texture into multiple mailboxes should result in sharing
549 // only a single texture also within a synchronized manager instance.
550 TEST_F(MailboxManagerSyncTest, SharedThroughMultipleMailboxes) {
551 const GLuint kNewTextureId = 1234;
552 InSequence sequence;
553
554 Texture* texture = DefineTexture();
555 Mailbox name1 = Mailbox::Generate();
556 Mailbox name2 = Mailbox::Generate();
557
558 manager_->ProduceTexture(name1, texture);
559
560 // Share
561 manager_->PushTextureUpdates(0);
562 EXPECT_CALL(*gl_, GenTextures(1, _))
563 .WillOnce(SetArgPointee<1>(kNewTextureId));
564 manager2_->PullTextureUpdates(0);
565 SetupUpdateTexParamExpectations(
566 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
567 Texture* new_texture = manager2_->ConsumeTexture(name1);
568 EXPECT_EQ(kNewTextureId, new_texture->service_id());
569
570 manager_->ProduceTexture(name2, texture);
571
572 // Synchronize
573 manager_->PushTextureUpdates(0);
574 manager2_->PullTextureUpdates(0);
575
576 // name2 should return the same texture
577 EXPECT_EQ(new_texture, manager2_->ConsumeTexture(name2));
578
579 // Even after destroying the source texture, the original mailbox should
580 // still exist.
581 DestroyTexture(texture);
582 EXPECT_EQ(new_texture, manager2_->ConsumeTexture(name1));
583 DestroyTexture(new_texture);
584 }
585
586 // A: produce texture1 into M, B: consume into new_texture
587 // B: produce texture2 into M, A: produce texture1 into M
588 // B: consume M should return new_texture
589 TEST_F(MailboxManagerSyncTest, ProduceBothWays) {
590 const GLuint kNewTextureId = 1234;
591 InSequence sequence;
592
593 Texture* texture1 = DefineTexture();
594 Texture* texture2 = DefineTexture();
595 Mailbox name = Mailbox::Generate();
596
597 manager_->ProduceTexture(name, texture1);
598
599 // Share
600 manager_->PushTextureUpdates(0);
601 EXPECT_CALL(*gl_, GenTextures(1, _))
602 .WillOnce(SetArgPointee<1>(kNewTextureId));
603 SetupUpdateTexParamExpectations(
604 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
605 Texture* new_texture = manager2_->ConsumeTexture(name);
606 EXPECT_EQ(kNewTextureId, new_texture->service_id());
607
608 // Clobber
609 manager2_->ProduceTexture(name, texture2);
610 manager_->ProduceTexture(name, texture1);
611
612 // Synchronize manager -> manager2
613 manager_->PushTextureUpdates(0);
614 manager2_->PullTextureUpdates(0);
615
616 // name should return the original texture, and not texture2 or a new one.
617 EXPECT_EQ(new_texture, manager2_->ConsumeTexture(name));
618
619 DestroyTexture(texture1);
620 DestroyTexture(texture2);
621 DestroyTexture(new_texture);
622 }
471 623
472 // TODO: Produce incomplete texture 624 // TODO: Produce incomplete texture
473 625
474 // TODO: Texture::level_infos_[][].size() 626 // TODO: Texture::level_infos_[][].size()
475 627
476 // TODO: unsupported targets and formats 628 // TODO: unsupported targets and formats
477 629
478 } // namespace gles2 630 } // namespace gles2
479 } // namespace gpu 631 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/mailbox_manager_sync.cc ('k') | gpu/command_buffer/service/mailbox_synchronizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698