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

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

Issue 1331843005: Implemented new fence syncs which replaces the old sync points. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added mojo README.chromium changes, fixed and added test for missing order number release case Created 5 years, 2 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
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/feature_info.h" 5 #include "gpu/command_buffer/service/feature_info.h"
6 #include "gpu/command_buffer/service/gpu_service_test.h" 6 #include "gpu/command_buffer/service/gpu_service_test.h"
7 #include "gpu/command_buffer/service/mailbox_manager_impl.h" 7 #include "gpu/command_buffer/service/mailbox_manager_impl.h"
8 #include "gpu/command_buffer/service/mailbox_manager_sync.h" 8 #include "gpu/command_buffer/service/mailbox_manager_sync.h"
9 #include "gpu/command_buffer/service/texture_manager.h" 9 #include "gpu/command_buffer/service/texture_manager.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/gl/gl_context_stub.h" 11 #include "ui/gl/gl_context_stub.h"
12 #include "ui/gl/gl_mock.h" 12 #include "ui/gl/gl_mock.h"
13 #include "ui/gl/gl_surface_stub.h" 13 #include "ui/gl/gl_surface_stub.h"
14 14
15 namespace gpu { 15 namespace gpu {
16 namespace gles2 { 16 namespace gles2 {
17 17
18 using namespace ::testing; 18 using namespace ::testing;
19 19
20 static const SyncToken g_sync_token = {
21 gpu::CommandBufferNamespace::GPU_IO,
22 123,
23 0
24 };
25
20 class MailboxManagerTest : public GpuServiceTest { 26 class MailboxManagerTest : public GpuServiceTest {
21 public: 27 public:
22 MailboxManagerTest() {} 28 MailboxManagerTest() {}
23 ~MailboxManagerTest() override {} 29 ~MailboxManagerTest() override {}
24 30
25 protected: 31 protected:
26 void SetUp() override { 32 void SetUp() override {
27 GpuServiceTest::SetUp(); 33 GpuServiceTest::SetUp();
28 feature_info_ = new FeatureInfo; 34 feature_info_ = new FeatureInfo;
29 manager_ = new MailboxManagerImpl; 35 manager_ = new MailboxManagerImpl;
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 TEST_F(MailboxManagerSyncTest, ProduceSyncDestroy) { 275 TEST_F(MailboxManagerSyncTest, ProduceSyncDestroy) {
270 InSequence sequence; 276 InSequence sequence;
271 277
272 Texture* texture = DefineTexture(); 278 Texture* texture = DefineTexture();
273 Mailbox name = Mailbox::Generate(); 279 Mailbox name = Mailbox::Generate();
274 280
275 manager_->ProduceTexture(name, texture); 281 manager_->ProduceTexture(name, texture);
276 EXPECT_EQ(texture, manager_->ConsumeTexture(name)); 282 EXPECT_EQ(texture, manager_->ConsumeTexture(name));
277 283
278 // Synchronize 284 // Synchronize
279 manager_->PushTextureUpdates(0); 285 manager_->PushTextureUpdates(g_sync_token);
280 manager2_->PullTextureUpdates(0); 286 manager2_->PullTextureUpdates(g_sync_token);
281 287
282 DestroyTexture(texture); 288 DestroyTexture(texture);
283 EXPECT_EQ(NULL, manager_->ConsumeTexture(name)); 289 EXPECT_EQ(NULL, manager_->ConsumeTexture(name));
284 EXPECT_EQ(NULL, manager2_->ConsumeTexture(name)); 290 EXPECT_EQ(NULL, manager2_->ConsumeTexture(name));
285 } 291 }
286 292
287 TEST_F(MailboxManagerSyncTest, ProduceSyncClobberDestroy) { 293 TEST_F(MailboxManagerSyncTest, ProduceSyncClobberDestroy) {
288 InSequence sequence; 294 InSequence sequence;
289 295
290 Texture* texture = DefineTexture(); 296 Texture* texture = DefineTexture();
291 Mailbox name = Mailbox::Generate(); 297 Mailbox name = Mailbox::Generate();
292 298
293 manager_->ProduceTexture(name, texture); 299 manager_->ProduceTexture(name, texture);
294 manager_->PushTextureUpdates(0); 300 manager_->PushTextureUpdates(g_sync_token);
295 301
296 // Clobber 302 // Clobber
297 Texture* old_texture = texture; 303 Texture* old_texture = texture;
298 texture = DefineTexture(); 304 texture = DefineTexture();
299 manager_->ProduceTexture(name, texture); 305 manager_->ProduceTexture(name, texture);
300 306
301 DestroyTexture(old_texture); 307 DestroyTexture(old_texture);
302 DestroyTexture(texture); 308 DestroyTexture(texture);
303 EXPECT_EQ(NULL, manager_->ConsumeTexture(name)); 309 EXPECT_EQ(NULL, manager_->ConsumeTexture(name));
304 EXPECT_EQ(NULL, manager2_->ConsumeTexture(name)); 310 EXPECT_EQ(NULL, manager2_->ConsumeTexture(name));
305 } 311 }
306 312
307 // Duplicates a texture into a second manager instance, and then 313 // Duplicates a texture into a second manager instance, and then
308 // makes sure a redefinition becomes visible there too. 314 // makes sure a redefinition becomes visible there too.
309 TEST_F(MailboxManagerSyncTest, ProduceConsumeResize) { 315 TEST_F(MailboxManagerSyncTest, ProduceConsumeResize) {
310 const GLuint kNewTextureId = 1234; 316 const GLuint kNewTextureId = 1234;
311 InSequence sequence; 317 InSequence sequence;
312 318
313 Texture* texture = DefineTexture(); 319 Texture* texture = DefineTexture();
314 Mailbox name = Mailbox::Generate(); 320 Mailbox name = Mailbox::Generate();
315 321
316 manager_->ProduceTexture(name, texture); 322 manager_->ProduceTexture(name, texture);
317 EXPECT_EQ(texture, manager_->ConsumeTexture(name)); 323 EXPECT_EQ(texture, manager_->ConsumeTexture(name));
318 324
319 // Synchronize 325 // Synchronize
320 manager_->PushTextureUpdates(0); 326 manager_->PushTextureUpdates(g_sync_token);
321 manager2_->PullTextureUpdates(0); 327 manager2_->PullTextureUpdates(g_sync_token);
322 328
323 EXPECT_CALL(*gl_, GenTextures(1, _)) 329 EXPECT_CALL(*gl_, GenTextures(1, _))
324 .WillOnce(SetArgPointee<1>(kNewTextureId)); 330 .WillOnce(SetArgPointee<1>(kNewTextureId));
325 SetupUpdateTexParamExpectations( 331 SetupUpdateTexParamExpectations(
326 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); 332 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
327 Texture* new_texture = manager2_->ConsumeTexture(name); 333 Texture* new_texture = manager2_->ConsumeTexture(name);
328 EXPECT_FALSE(new_texture == NULL); 334 EXPECT_FALSE(new_texture == NULL);
329 EXPECT_NE(texture, new_texture); 335 EXPECT_NE(texture, new_texture);
330 EXPECT_EQ(kNewTextureId, new_texture->service_id()); 336 EXPECT_EQ(kNewTextureId, new_texture->service_id());
331 337
332 // Resize original texture 338 // Resize original texture
333 SetLevelInfo(texture, GL_TEXTURE_2D, 0, GL_RGBA, 16, 32, 1, 0, GL_RGBA, 339 SetLevelInfo(texture, GL_TEXTURE_2D, 0, GL_RGBA, 16, 32, 1, 0, GL_RGBA,
334 GL_UNSIGNED_BYTE, gfx::Rect(16, 32)); 340 GL_UNSIGNED_BYTE, gfx::Rect(16, 32));
335 // Should have been orphaned 341 // Should have been orphaned
336 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL); 342 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
337 343
338 // Synchronize again 344 // Synchronize again
339 manager_->PushTextureUpdates(0); 345 manager_->PushTextureUpdates(g_sync_token);
340 SetupUpdateTexParamExpectations( 346 SetupUpdateTexParamExpectations(
341 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); 347 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
342 manager2_->PullTextureUpdates(0); 348 manager2_->PullTextureUpdates(g_sync_token);
343 GLsizei width, height; 349 GLsizei width, height;
344 new_texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height, nullptr); 350 new_texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height, nullptr);
345 EXPECT_EQ(16, width); 351 EXPECT_EQ(16, width);
346 EXPECT_EQ(32, height); 352 EXPECT_EQ(32, height);
347 353
348 // Should have gotten a new attachment 354 // Should have gotten a new attachment
349 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) != NULL); 355 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) != NULL);
350 // Resize original texture again.... 356 // Resize original texture again....
351 SetLevelInfo(texture, GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 1, 0, GL_RGBA, 357 SetLevelInfo(texture, GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 1, 0, GL_RGBA,
352 GL_UNSIGNED_BYTE, gfx::Rect(64, 64)); 358 GL_UNSIGNED_BYTE, gfx::Rect(64, 64));
353 // ...and immediately delete the texture which should save the changes. 359 // ...and immediately delete the texture which should save the changes.
354 SetupUpdateTexParamExpectations( 360 SetupUpdateTexParamExpectations(
355 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); 361 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
356 DestroyTexture(texture); 362 DestroyTexture(texture);
357 363
358 // Should be still around since there is a ref from manager2 364 // Should be still around since there is a ref from manager2
359 EXPECT_EQ(new_texture, manager2_->ConsumeTexture(name)); 365 EXPECT_EQ(new_texture, manager2_->ConsumeTexture(name));
360 366
361 // The last change to the texture should be visible without a sync point (i.e. 367 // The last change to the texture should be visible without a sync point (i.e.
362 // push). 368 // push).
363 manager2_->PullTextureUpdates(0); 369 manager2_->PullTextureUpdates(g_sync_token);
364 new_texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height, nullptr); 370 new_texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height, nullptr);
365 EXPECT_EQ(64, width); 371 EXPECT_EQ(64, width);
366 EXPECT_EQ(64, height); 372 EXPECT_EQ(64, height);
367 373
368 DestroyTexture(new_texture); 374 DestroyTexture(new_texture);
369 EXPECT_EQ(NULL, manager_->ConsumeTexture(name)); 375 EXPECT_EQ(NULL, manager_->ConsumeTexture(name));
370 EXPECT_EQ(NULL, manager2_->ConsumeTexture(name)); 376 EXPECT_EQ(NULL, manager2_->ConsumeTexture(name));
371 } 377 }
372 378
373 // Makes sure changes are correctly published even when updates are 379 // Makes sure changes are correctly published even when updates are
374 // pushed in both directions, i.e. makes sure we don't clobber a shared 380 // pushed in both directions, i.e. makes sure we don't clobber a shared
375 // texture definition with an older version. 381 // texture definition with an older version.
376 TEST_F(MailboxManagerSyncTest, ProduceConsumeBidirectional) { 382 TEST_F(MailboxManagerSyncTest, ProduceConsumeBidirectional) {
377 const GLuint kNewTextureId1 = 1234; 383 const GLuint kNewTextureId1 = 1234;
378 const GLuint kNewTextureId2 = 4321; 384 const GLuint kNewTextureId2 = 4321;
379 385
380 Texture* texture1 = DefineTexture(); 386 Texture* texture1 = DefineTexture();
381 Mailbox name1 = Mailbox::Generate(); 387 Mailbox name1 = Mailbox::Generate();
382 Texture* texture2 = DefineTexture(); 388 Texture* texture2 = DefineTexture();
383 Mailbox name2 = Mailbox::Generate(); 389 Mailbox name2 = Mailbox::Generate();
384 Texture* new_texture1 = NULL; 390 Texture* new_texture1 = NULL;
385 Texture* new_texture2 = NULL; 391 Texture* new_texture2 = NULL;
386 392
387 manager_->ProduceTexture(name1, texture1); 393 manager_->ProduceTexture(name1, texture1);
388 manager2_->ProduceTexture(name2, texture2); 394 manager2_->ProduceTexture(name2, texture2);
389 395
390 // Make visible. 396 // Make visible.
391 manager_->PushTextureUpdates(0); 397 manager_->PushTextureUpdates(g_sync_token);
392 manager2_->PushTextureUpdates(0); 398 manager2_->PushTextureUpdates(g_sync_token);
393 399
394 // Create textures in the other manager instances for texture1 and texture2, 400 // Create textures in the other manager instances for texture1 and texture2,
395 // respectively to create a real sharing scenario. Otherwise, there would 401 // respectively to create a real sharing scenario. Otherwise, there would
396 // never be conflicting updates/pushes. 402 // never be conflicting updates/pushes.
397 { 403 {
398 InSequence sequence; 404 InSequence sequence;
399 EXPECT_CALL(*gl_, GenTextures(1, _)) 405 EXPECT_CALL(*gl_, GenTextures(1, _))
400 .WillOnce(SetArgPointee<1>(kNewTextureId1)); 406 .WillOnce(SetArgPointee<1>(kNewTextureId1));
401 SetupUpdateTexParamExpectations( 407 SetupUpdateTexParamExpectations(
402 kNewTextureId1, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); 408 kNewTextureId1, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
403 new_texture1 = manager2_->ConsumeTexture(name1); 409 new_texture1 = manager2_->ConsumeTexture(name1);
404 EXPECT_CALL(*gl_, GenTextures(1, _)) 410 EXPECT_CALL(*gl_, GenTextures(1, _))
405 .WillOnce(SetArgPointee<1>(kNewTextureId2)); 411 .WillOnce(SetArgPointee<1>(kNewTextureId2));
406 SetupUpdateTexParamExpectations( 412 SetupUpdateTexParamExpectations(
407 kNewTextureId2, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); 413 kNewTextureId2, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
408 new_texture2 = manager_->ConsumeTexture(name2); 414 new_texture2 = manager_->ConsumeTexture(name2);
409 } 415 }
410 EXPECT_EQ(kNewTextureId1, new_texture1->service_id()); 416 EXPECT_EQ(kNewTextureId1, new_texture1->service_id());
411 EXPECT_EQ(kNewTextureId2, new_texture2->service_id()); 417 EXPECT_EQ(kNewTextureId2, new_texture2->service_id());
412 418
413 // Make a change to texture1 419 // Make a change to texture1
414 DCHECK_EQ(static_cast<GLuint>(GL_LINEAR), texture1->min_filter()); 420 DCHECK_EQ(static_cast<GLuint>(GL_LINEAR), texture1->min_filter());
415 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), 421 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR),
416 SetParameter(texture1, GL_TEXTURE_MIN_FILTER, GL_NEAREST)); 422 SetParameter(texture1, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
417 423
418 // Make sure this does not clobber it with the previous version we pushed. 424 // Make sure this does not clobber it with the previous version we pushed.
419 manager_->PullTextureUpdates(0); 425 manager_->PullTextureUpdates(g_sync_token);
420 426
421 // Make a change to texture2 427 // Make a change to texture2
422 DCHECK_EQ(static_cast<GLuint>(GL_LINEAR), texture2->mag_filter()); 428 DCHECK_EQ(static_cast<GLuint>(GL_LINEAR), texture2->mag_filter());
423 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), 429 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR),
424 SetParameter(texture2, GL_TEXTURE_MAG_FILTER, GL_NEAREST)); 430 SetParameter(texture2, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
425 431
426 Mock::VerifyAndClearExpectations(gl_.get()); 432 Mock::VerifyAndClearExpectations(gl_.get());
427 433
428 // Synchronize in both directions 434 // Synchronize in both directions
429 manager_->PushTextureUpdates(0); 435 manager_->PushTextureUpdates(g_sync_token);
430 manager2_->PushTextureUpdates(0); 436 manager2_->PushTextureUpdates(g_sync_token);
431 // manager1 should see the change to texture2 mag_filter being applied. 437 // manager1 should see the change to texture2 mag_filter being applied.
432 SetupUpdateTexParamExpectations( 438 SetupUpdateTexParamExpectations(
433 new_texture2->service_id(), GL_LINEAR, GL_NEAREST, GL_REPEAT, GL_REPEAT); 439 new_texture2->service_id(), GL_LINEAR, GL_NEAREST, GL_REPEAT, GL_REPEAT);
434 manager_->PullTextureUpdates(0); 440 manager_->PullTextureUpdates(g_sync_token);
435 // manager2 should see the change to texture1 min_filter being applied. 441 // manager2 should see the change to texture1 min_filter being applied.
436 SetupUpdateTexParamExpectations( 442 SetupUpdateTexParamExpectations(
437 new_texture1->service_id(), GL_NEAREST, GL_LINEAR, GL_REPEAT, GL_REPEAT); 443 new_texture1->service_id(), GL_NEAREST, GL_LINEAR, GL_REPEAT, GL_REPEAT);
438 manager2_->PullTextureUpdates(0); 444 manager2_->PullTextureUpdates(g_sync_token);
439 445
440 DestroyTexture(texture1); 446 DestroyTexture(texture1);
441 DestroyTexture(texture2); 447 DestroyTexture(texture2);
442 DestroyTexture(new_texture1); 448 DestroyTexture(new_texture1);
443 DestroyTexture(new_texture2); 449 DestroyTexture(new_texture2);
444 } 450 }
445 451
446 // If a texture is shared with another manager instance, but the mailbox 452 // If a texture is shared with another manager instance, but the mailbox
447 // is then clobbered with a different texture in the source context, this should 453 // is then clobbered with a different texture in the source context, this should
448 // disconnect the earlier texture from updates. 454 // disconnect the earlier texture from updates.
449 TEST_F(MailboxManagerSyncTest, ProduceAndClobber) { 455 TEST_F(MailboxManagerSyncTest, ProduceAndClobber) {
450 const GLuint kNewTextureId = 1234; 456 const GLuint kNewTextureId = 1234;
451 InSequence sequence; 457 InSequence sequence;
452 458
453 Texture* texture = DefineTexture(); 459 Texture* texture = DefineTexture();
454 Mailbox name = Mailbox::Generate(); 460 Mailbox name = Mailbox::Generate();
455 461
456 manager_->ProduceTexture(name, texture); 462 manager_->ProduceTexture(name, texture);
457 EXPECT_EQ(texture, manager_->ConsumeTexture(name)); 463 EXPECT_EQ(texture, manager_->ConsumeTexture(name));
458 464
459 // Synchronize 465 // Synchronize
460 manager_->PushTextureUpdates(0); 466 manager_->PushTextureUpdates(g_sync_token);
461 manager2_->PullTextureUpdates(0); 467 manager2_->PullTextureUpdates(g_sync_token);
462 468
463 EXPECT_CALL(*gl_, GenTextures(1, _)) 469 EXPECT_CALL(*gl_, GenTextures(1, _))
464 .WillOnce(SetArgPointee<1>(kNewTextureId)); 470 .WillOnce(SetArgPointee<1>(kNewTextureId));
465 SetupUpdateTexParamExpectations( 471 SetupUpdateTexParamExpectations(
466 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); 472 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
467 Texture* new_texture = manager2_->ConsumeTexture(name); 473 Texture* new_texture = manager2_->ConsumeTexture(name);
468 EXPECT_FALSE(new_texture == NULL); 474 EXPECT_FALSE(new_texture == NULL);
469 EXPECT_NE(texture, new_texture); 475 EXPECT_NE(texture, new_texture);
470 EXPECT_EQ(kNewTextureId, new_texture->service_id()); 476 EXPECT_EQ(kNewTextureId, new_texture->service_id());
471 477
472 Texture* old_texture = texture; 478 Texture* old_texture = texture;
473 texture = DefineTexture(); 479 texture = DefineTexture();
474 manager_->ProduceTexture(name, texture); 480 manager_->ProduceTexture(name, texture);
475 481
476 // Make a change to the new texture 482 // Make a change to the new texture
477 DCHECK_EQ(static_cast<GLuint>(GL_LINEAR), texture->min_filter()); 483 DCHECK_EQ(static_cast<GLuint>(GL_LINEAR), texture->min_filter());
478 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), 484 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR),
479 SetParameter(texture, GL_TEXTURE_MIN_FILTER, GL_NEAREST)); 485 SetParameter(texture, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
480 486
481 // Synchronize in both directions - no changes, since it's not shared 487 // Synchronize in both directions - no changes, since it's not shared
482 manager_->PushTextureUpdates(0); 488 manager_->PushTextureUpdates(g_sync_token);
483 manager2_->PullTextureUpdates(0); 489 manager2_->PullTextureUpdates(g_sync_token);
484 EXPECT_EQ(static_cast<GLuint>(GL_LINEAR), new_texture->min_filter()); 490 EXPECT_EQ(static_cast<GLuint>(GL_LINEAR), new_texture->min_filter());
485 491
486 // Make a change to the previously shared texture 492 // Make a change to the previously shared texture
487 DCHECK_EQ(static_cast<GLuint>(GL_LINEAR), old_texture->mag_filter()); 493 DCHECK_EQ(static_cast<GLuint>(GL_LINEAR), old_texture->mag_filter());
488 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), 494 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR),
489 SetParameter(old_texture, GL_TEXTURE_MAG_FILTER, GL_NEAREST)); 495 SetParameter(old_texture, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
490 496
491 // Synchronize and expect update 497 // Synchronize and expect update
492 manager_->PushTextureUpdates(0); 498 manager_->PushTextureUpdates(g_sync_token);
493 SetupUpdateTexParamExpectations( 499 SetupUpdateTexParamExpectations(
494 new_texture->service_id(), GL_LINEAR, GL_NEAREST, GL_REPEAT, GL_REPEAT); 500 new_texture->service_id(), GL_LINEAR, GL_NEAREST, GL_REPEAT, GL_REPEAT);
495 manager2_->PullTextureUpdates(0); 501 manager2_->PullTextureUpdates(g_sync_token);
496 502
497 EXPECT_CALL(*gl_, GenTextures(1, _)) 503 EXPECT_CALL(*gl_, GenTextures(1, _))
498 .WillOnce(SetArgPointee<1>(kNewTextureId)); 504 .WillOnce(SetArgPointee<1>(kNewTextureId));
499 SetupUpdateTexParamExpectations( 505 SetupUpdateTexParamExpectations(
500 kNewTextureId, GL_NEAREST, GL_LINEAR, GL_REPEAT, GL_REPEAT); 506 kNewTextureId, GL_NEAREST, GL_LINEAR, GL_REPEAT, GL_REPEAT);
501 Texture* tmp_texture = manager2_->ConsumeTexture(name); 507 Texture* tmp_texture = manager2_->ConsumeTexture(name);
502 EXPECT_NE(new_texture, tmp_texture); 508 EXPECT_NE(new_texture, tmp_texture);
503 DestroyTexture(tmp_texture); 509 DestroyTexture(tmp_texture);
504 510
505 DestroyTexture(old_texture); 511 DestroyTexture(old_texture);
506 DestroyTexture(texture); 512 DestroyTexture(texture);
507 DestroyTexture(new_texture); 513 DestroyTexture(new_texture);
508 514
509 EXPECT_EQ(NULL, manager_->ConsumeTexture(name)); 515 EXPECT_EQ(NULL, manager_->ConsumeTexture(name));
510 EXPECT_EQ(NULL, manager2_->ConsumeTexture(name)); 516 EXPECT_EQ(NULL, manager2_->ConsumeTexture(name));
511 } 517 }
512 518
513 TEST_F(MailboxManagerSyncTest, ClearedStateSynced) { 519 TEST_F(MailboxManagerSyncTest, ClearedStateSynced) {
514 const GLuint kNewTextureId = 1234; 520 const GLuint kNewTextureId = 1234;
515 521
516 Texture* texture = DefineTexture(); 522 Texture* texture = DefineTexture();
517 EXPECT_TRUE(texture->SafeToRenderFrom()); 523 EXPECT_TRUE(texture->SafeToRenderFrom());
518 524
519 Mailbox name = Mailbox::Generate(); 525 Mailbox name = Mailbox::Generate();
520 526
521 manager_->ProduceTexture(name, texture); 527 manager_->ProduceTexture(name, texture);
522 EXPECT_EQ(texture, manager_->ConsumeTexture(name)); 528 EXPECT_EQ(texture, manager_->ConsumeTexture(name));
523 529
524 // Synchronize 530 // Synchronize
525 manager_->PushTextureUpdates(0); 531 manager_->PushTextureUpdates(g_sync_token);
526 manager2_->PullTextureUpdates(0); 532 manager2_->PullTextureUpdates(g_sync_token);
527 533
528 EXPECT_CALL(*gl_, GenTextures(1, _)) 534 EXPECT_CALL(*gl_, GenTextures(1, _))
529 .WillOnce(SetArgPointee<1>(kNewTextureId)); 535 .WillOnce(SetArgPointee<1>(kNewTextureId));
530 SetupUpdateTexParamExpectations( 536 SetupUpdateTexParamExpectations(
531 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); 537 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
532 Texture* new_texture = manager2_->ConsumeTexture(name); 538 Texture* new_texture = manager2_->ConsumeTexture(name);
533 EXPECT_FALSE(new_texture == NULL); 539 EXPECT_FALSE(new_texture == NULL);
534 EXPECT_NE(texture, new_texture); 540 EXPECT_NE(texture, new_texture);
535 EXPECT_EQ(kNewTextureId, new_texture->service_id()); 541 EXPECT_EQ(kNewTextureId, new_texture->service_id());
536 EXPECT_TRUE(texture->SafeToRenderFrom()); 542 EXPECT_TRUE(texture->SafeToRenderFrom());
537 543
538 // Change cleared to false. 544 // Change cleared to false.
539 SetLevelCleared(texture, texture->target(), 0, false); 545 SetLevelCleared(texture, texture->target(), 0, false);
540 EXPECT_FALSE(texture->SafeToRenderFrom()); 546 EXPECT_FALSE(texture->SafeToRenderFrom());
541 547
542 // Synchronize 548 // Synchronize
543 manager_->PushTextureUpdates(0); 549 manager_->PushTextureUpdates(g_sync_token);
544 SetupUpdateTexParamExpectations( 550 SetupUpdateTexParamExpectations(
545 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); 551 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
546 manager2_->PullTextureUpdates(0); 552 manager2_->PullTextureUpdates(g_sync_token);
547 553
548 // Cleared state should be synced. 554 // Cleared state should be synced.
549 EXPECT_FALSE(new_texture->SafeToRenderFrom()); 555 EXPECT_FALSE(new_texture->SafeToRenderFrom());
550 556
551 DestroyTexture(texture); 557 DestroyTexture(texture);
552 DestroyTexture(new_texture); 558 DestroyTexture(new_texture);
553 559
554 EXPECT_EQ(NULL, manager_->ConsumeTexture(name)); 560 EXPECT_EQ(NULL, manager_->ConsumeTexture(name));
555 EXPECT_EQ(NULL, manager2_->ConsumeTexture(name)); 561 EXPECT_EQ(NULL, manager2_->ConsumeTexture(name));
556 } 562 }
557 563
558 TEST_F(MailboxManagerSyncTest, SyncIncompleteTexture) { 564 TEST_F(MailboxManagerSyncTest, SyncIncompleteTexture) {
559 const GLuint kNewTextureId = 1234; 565 const GLuint kNewTextureId = 1234;
560 566
561 // Create but not define texture. 567 // Create but not define texture.
562 Texture* texture = CreateTexture(); 568 Texture* texture = CreateTexture();
563 SetTarget(texture, GL_TEXTURE_2D, 1); 569 SetTarget(texture, GL_TEXTURE_2D, 1);
564 EXPECT_FALSE(texture->IsDefined()); 570 EXPECT_FALSE(texture->IsDefined());
565 571
566 Mailbox name = Mailbox::Generate(); 572 Mailbox name = Mailbox::Generate();
567 manager_->ProduceTexture(name, texture); 573 manager_->ProduceTexture(name, texture);
568 EXPECT_EQ(texture, manager_->ConsumeTexture(name)); 574 EXPECT_EQ(texture, manager_->ConsumeTexture(name));
569 575
570 // Synchronize 576 // Synchronize
571 manager_->PushTextureUpdates(0); 577 manager_->PushTextureUpdates(g_sync_token);
572 manager2_->PullTextureUpdates(0); 578 manager2_->PullTextureUpdates(g_sync_token);
573 579
574 // Should sync to new texture which is not defined. 580 // Should sync to new texture which is not defined.
575 EXPECT_CALL(*gl_, GenTextures(1, _)) 581 EXPECT_CALL(*gl_, GenTextures(1, _))
576 .WillOnce(SetArgPointee<1>(kNewTextureId)); 582 .WillOnce(SetArgPointee<1>(kNewTextureId));
577 SetupUpdateTexParamExpectations(kNewTextureId, texture->min_filter(), 583 SetupUpdateTexParamExpectations(kNewTextureId, texture->min_filter(),
578 texture->mag_filter(), texture->wrap_s(), 584 texture->mag_filter(), texture->wrap_s(),
579 texture->wrap_t()); 585 texture->wrap_t());
580 Texture* new_texture = manager2_->ConsumeTexture(name); 586 Texture* new_texture = manager2_->ConsumeTexture(name);
581 ASSERT_TRUE(new_texture); 587 ASSERT_TRUE(new_texture);
582 EXPECT_NE(texture, new_texture); 588 EXPECT_NE(texture, new_texture);
583 EXPECT_EQ(kNewTextureId, new_texture->service_id()); 589 EXPECT_EQ(kNewTextureId, new_texture->service_id());
584 EXPECT_FALSE(new_texture->IsDefined()); 590 EXPECT_FALSE(new_texture->IsDefined());
585 591
586 // Change cleared to false. 592 // Change cleared to false.
587 SetLevelInfo(texture, GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, 593 SetLevelInfo(texture, GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA,
588 GL_UNSIGNED_BYTE, gfx::Rect(1, 1)); 594 GL_UNSIGNED_BYTE, gfx::Rect(1, 1));
589 SetParameter(texture, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 595 SetParameter(texture, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
590 SetParameter(texture, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 596 SetParameter(texture, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
591 EXPECT_TRUE(texture->IsDefined()); 597 EXPECT_TRUE(texture->IsDefined());
592 598
593 // Synchronize 599 // Synchronize
594 manager_->PushTextureUpdates(0); 600 manager_->PushTextureUpdates(g_sync_token);
595 SetupUpdateTexParamExpectations( 601 SetupUpdateTexParamExpectations(
596 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); 602 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
597 manager2_->PullTextureUpdates(0); 603 manager2_->PullTextureUpdates(g_sync_token);
598 604
599 // Cleared state should be synced. 605 // Cleared state should be synced.
600 EXPECT_TRUE(new_texture->IsDefined()); 606 EXPECT_TRUE(new_texture->IsDefined());
601 607
602 DestroyTexture(texture); 608 DestroyTexture(texture);
603 DestroyTexture(new_texture); 609 DestroyTexture(new_texture);
604 610
605 EXPECT_EQ(NULL, manager_->ConsumeTexture(name)); 611 EXPECT_EQ(NULL, manager_->ConsumeTexture(name));
606 EXPECT_EQ(NULL, manager2_->ConsumeTexture(name)); 612 EXPECT_EQ(NULL, manager2_->ConsumeTexture(name));
607 } 613 }
608 614
609 // Putting the same texture into multiple mailboxes should result in sharing 615 // Putting the same texture into multiple mailboxes should result in sharing
610 // only a single texture also within a synchronized manager instance. 616 // only a single texture also within a synchronized manager instance.
611 TEST_F(MailboxManagerSyncTest, SharedThroughMultipleMailboxes) { 617 TEST_F(MailboxManagerSyncTest, SharedThroughMultipleMailboxes) {
612 const GLuint kNewTextureId = 1234; 618 const GLuint kNewTextureId = 1234;
613 InSequence sequence; 619 InSequence sequence;
614 620
615 Texture* texture = DefineTexture(); 621 Texture* texture = DefineTexture();
616 Mailbox name1 = Mailbox::Generate(); 622 Mailbox name1 = Mailbox::Generate();
617 Mailbox name2 = Mailbox::Generate(); 623 Mailbox name2 = Mailbox::Generate();
618 624
619 manager_->ProduceTexture(name1, texture); 625 manager_->ProduceTexture(name1, texture);
620 626
621 // Share 627 // Share
622 manager_->PushTextureUpdates(0); 628 manager_->PushTextureUpdates(g_sync_token);
623 EXPECT_CALL(*gl_, GenTextures(1, _)) 629 EXPECT_CALL(*gl_, GenTextures(1, _))
624 .WillOnce(SetArgPointee<1>(kNewTextureId)); 630 .WillOnce(SetArgPointee<1>(kNewTextureId));
625 manager2_->PullTextureUpdates(0); 631 manager2_->PullTextureUpdates(g_sync_token);
626 SetupUpdateTexParamExpectations( 632 SetupUpdateTexParamExpectations(
627 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); 633 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
628 Texture* new_texture = manager2_->ConsumeTexture(name1); 634 Texture* new_texture = manager2_->ConsumeTexture(name1);
629 EXPECT_EQ(kNewTextureId, new_texture->service_id()); 635 EXPECT_EQ(kNewTextureId, new_texture->service_id());
630 636
631 manager_->ProduceTexture(name2, texture); 637 manager_->ProduceTexture(name2, texture);
632 638
633 // Synchronize 639 // Synchronize
634 manager_->PushTextureUpdates(0); 640 manager_->PushTextureUpdates(g_sync_token);
635 manager2_->PullTextureUpdates(0); 641 manager2_->PullTextureUpdates(g_sync_token);
636 642
637 // name2 should return the same texture 643 // name2 should return the same texture
638 EXPECT_EQ(new_texture, manager2_->ConsumeTexture(name2)); 644 EXPECT_EQ(new_texture, manager2_->ConsumeTexture(name2));
639 645
640 // Even after destroying the source texture, the original mailbox should 646 // Even after destroying the source texture, the original mailbox should
641 // still exist. 647 // still exist.
642 DestroyTexture(texture); 648 DestroyTexture(texture);
643 EXPECT_EQ(new_texture, manager2_->ConsumeTexture(name1)); 649 EXPECT_EQ(new_texture, manager2_->ConsumeTexture(name1));
644 DestroyTexture(new_texture); 650 DestroyTexture(new_texture);
645 } 651 }
646 652
647 // A: produce texture1 into M, B: consume into new_texture 653 // A: produce texture1 into M, B: consume into new_texture
648 // B: produce texture2 into M, A: produce texture1 into M 654 // B: produce texture2 into M, A: produce texture1 into M
649 // B: consume M should return new_texture 655 // B: consume M should return new_texture
650 TEST_F(MailboxManagerSyncTest, ProduceBothWays) { 656 TEST_F(MailboxManagerSyncTest, ProduceBothWays) {
651 const GLuint kNewTextureId = 1234; 657 const GLuint kNewTextureId = 1234;
652 InSequence sequence; 658 InSequence sequence;
653 659
654 Texture* texture1 = DefineTexture(); 660 Texture* texture1 = DefineTexture();
655 Texture* texture2 = DefineTexture(); 661 Texture* texture2 = DefineTexture();
656 Mailbox name = Mailbox::Generate(); 662 Mailbox name = Mailbox::Generate();
657 663
658 manager_->ProduceTexture(name, texture1); 664 manager_->ProduceTexture(name, texture1);
659 665
660 // Share 666 // Share
661 manager_->PushTextureUpdates(0); 667 manager_->PushTextureUpdates(g_sync_token);
662 EXPECT_CALL(*gl_, GenTextures(1, _)) 668 EXPECT_CALL(*gl_, GenTextures(1, _))
663 .WillOnce(SetArgPointee<1>(kNewTextureId)); 669 .WillOnce(SetArgPointee<1>(kNewTextureId));
664 SetupUpdateTexParamExpectations( 670 SetupUpdateTexParamExpectations(
665 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); 671 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT);
666 Texture* new_texture = manager2_->ConsumeTexture(name); 672 Texture* new_texture = manager2_->ConsumeTexture(name);
667 EXPECT_EQ(kNewTextureId, new_texture->service_id()); 673 EXPECT_EQ(kNewTextureId, new_texture->service_id());
668 674
669 // Clobber 675 // Clobber
670 manager2_->ProduceTexture(name, texture2); 676 manager2_->ProduceTexture(name, texture2);
671 manager_->ProduceTexture(name, texture1); 677 manager_->ProduceTexture(name, texture1);
672 678
673 // Synchronize manager -> manager2 679 // Synchronize manager -> manager2
674 manager_->PushTextureUpdates(0); 680 manager_->PushTextureUpdates(g_sync_token);
675 manager2_->PullTextureUpdates(0); 681 manager2_->PullTextureUpdates(g_sync_token);
676 682
677 // name should return the original texture, and not texture2 or a new one. 683 // name should return the original texture, and not texture2 or a new one.
678 EXPECT_EQ(new_texture, manager2_->ConsumeTexture(name)); 684 EXPECT_EQ(new_texture, manager2_->ConsumeTexture(name));
679 685
680 DestroyTexture(texture1); 686 DestroyTexture(texture1);
681 DestroyTexture(texture2); 687 DestroyTexture(texture2);
682 DestroyTexture(new_texture); 688 DestroyTexture(new_texture);
683 } 689 }
684 690
685 // TODO: Texture::level_infos_[][].size() 691 // TODO: Texture::level_infos_[][].size()
686 692
687 // TODO: unsupported targets and formats 693 // TODO: unsupported targets and formats
688 694
689 } // namespace gles2 695 } // namespace gles2
690 } // namespace gpu 696 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698