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