| 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/mailbox_manager.h" | 5 #include "gpu/command_buffer/service/mailbox_manager.h" |
| 6 | 6 |
| 7 #include "gpu/command_buffer/service/feature_info.h" | 7 #include "gpu/command_buffer/service/feature_info.h" |
| 8 #include "gpu/command_buffer/service/gpu_service_test.h" | 8 #include "gpu/command_buffer/service/gpu_service_test.h" |
| 9 #include "gpu/command_buffer/service/mailbox_synchronizer.h" | 9 #include "gpu/command_buffer/service/mailbox_synchronizer.h" |
| 10 #include "gpu/command_buffer/service/texture_manager.h" | 10 #include "gpu/command_buffer/service/texture_manager.h" |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 TEST_F(MailboxManagerSyncTest, ProduceSyncDestroy) { | 293 TEST_F(MailboxManagerSyncTest, ProduceSyncDestroy) { |
| 294 InSequence sequence; | 294 InSequence sequence; |
| 295 | 295 |
| 296 Texture* texture = DefineTexture(); | 296 Texture* texture = DefineTexture(); |
| 297 Mailbox name = Mailbox::Generate(); | 297 Mailbox name = Mailbox::Generate(); |
| 298 | 298 |
| 299 manager_->ProduceTexture(GL_TEXTURE_2D, name, texture); | 299 manager_->ProduceTexture(GL_TEXTURE_2D, name, texture); |
| 300 EXPECT_EQ(texture, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); | 300 EXPECT_EQ(texture, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); |
| 301 | 301 |
| 302 // Synchronize | 302 // Synchronize |
| 303 manager_->PushTextureUpdates(); | 303 manager_->PushTextureUpdates(0); |
| 304 manager2_->PullTextureUpdates(); | 304 manager2_->PullTextureUpdates(0); |
| 305 | 305 |
| 306 DestroyTexture(texture); | 306 DestroyTexture(texture); |
| 307 EXPECT_EQ(NULL, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); | 307 EXPECT_EQ(NULL, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); |
| 308 EXPECT_EQ(NULL, manager2_->ConsumeTexture(GL_TEXTURE_2D, name)); | 308 EXPECT_EQ(NULL, manager2_->ConsumeTexture(GL_TEXTURE_2D, name)); |
| 309 } | 309 } |
| 310 | 310 |
| 311 // Duplicates a texture into a second manager instance, and then | 311 // Duplicates a texture into a second manager instance, and then |
| 312 // makes sure a redefinition becomes visible there too. | 312 // makes sure a redefinition becomes visible there too. |
| 313 TEST_F(MailboxManagerSyncTest, ProduceConsumeResize) { | 313 TEST_F(MailboxManagerSyncTest, ProduceConsumeResize) { |
| 314 const GLuint kNewTextureId = 1234; | 314 const GLuint kNewTextureId = 1234; |
| 315 InSequence sequence; | 315 InSequence sequence; |
| 316 | 316 |
| 317 Texture* texture = DefineTexture(); | 317 Texture* texture = DefineTexture(); |
| 318 Mailbox name = Mailbox::Generate(); | 318 Mailbox name = Mailbox::Generate(); |
| 319 | 319 |
| 320 manager_->ProduceTexture(GL_TEXTURE_2D, name, texture); | 320 manager_->ProduceTexture(GL_TEXTURE_2D, name, texture); |
| 321 EXPECT_EQ(texture, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); | 321 EXPECT_EQ(texture, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); |
| 322 | 322 |
| 323 // Synchronize | 323 // Synchronize |
| 324 manager_->PushTextureUpdates(); | 324 manager_->PushTextureUpdates(0); |
| 325 manager2_->PullTextureUpdates(); | 325 manager2_->PullTextureUpdates(0); |
| 326 | 326 |
| 327 EXPECT_CALL(*gl_, GenTextures(1, _)) | 327 EXPECT_CALL(*gl_, GenTextures(1, _)) |
| 328 .WillOnce(SetArgPointee<1>(kNewTextureId)); | 328 .WillOnce(SetArgPointee<1>(kNewTextureId)); |
| 329 SetupUpdateTexParamExpectations( | 329 SetupUpdateTexParamExpectations( |
| 330 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); | 330 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); |
| 331 Texture* new_texture = manager2_->ConsumeTexture(GL_TEXTURE_2D, name); | 331 Texture* new_texture = manager2_->ConsumeTexture(GL_TEXTURE_2D, name); |
| 332 EXPECT_FALSE(new_texture == NULL); | 332 EXPECT_FALSE(new_texture == NULL); |
| 333 EXPECT_NE(texture, new_texture); | 333 EXPECT_NE(texture, new_texture); |
| 334 EXPECT_EQ(kNewTextureId, new_texture->service_id()); | 334 EXPECT_EQ(kNewTextureId, new_texture->service_id()); |
| 335 | 335 |
| 336 // Resize original texture | 336 // Resize original texture |
| 337 SetLevelInfo(texture, | 337 SetLevelInfo(texture, |
| 338 GL_TEXTURE_2D, | 338 GL_TEXTURE_2D, |
| 339 0, | 339 0, |
| 340 GL_RGBA, | 340 GL_RGBA, |
| 341 16, | 341 16, |
| 342 32, | 342 32, |
| 343 1, | 343 1, |
| 344 0, | 344 0, |
| 345 GL_RGBA, | 345 GL_RGBA, |
| 346 GL_UNSIGNED_BYTE, | 346 GL_UNSIGNED_BYTE, |
| 347 true); | 347 true); |
| 348 // Should have been orphaned | 348 // Should have been orphaned |
| 349 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL); | 349 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL); |
| 350 | 350 |
| 351 // Synchronize again | 351 // Synchronize again |
| 352 manager_->PushTextureUpdates(); | 352 manager_->PushTextureUpdates(0); |
| 353 SetupUpdateTexParamExpectations( | 353 SetupUpdateTexParamExpectations( |
| 354 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); | 354 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); |
| 355 manager2_->PullTextureUpdates(); | 355 manager2_->PullTextureUpdates(0); |
| 356 GLsizei width, height; | 356 GLsizei width, height; |
| 357 new_texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height); | 357 new_texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height); |
| 358 EXPECT_EQ(16, width); | 358 EXPECT_EQ(16, width); |
| 359 EXPECT_EQ(32, height); | 359 EXPECT_EQ(32, height); |
| 360 | 360 |
| 361 // Should have gotten a new attachment | 361 // Should have gotten a new attachment |
| 362 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) != NULL); | 362 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) != NULL); |
| 363 // Resize original texture again.... | 363 // Resize original texture again.... |
| 364 SetLevelInfo(texture, | 364 SetLevelInfo(texture, |
| 365 GL_TEXTURE_2D, | 365 GL_TEXTURE_2D, |
| 366 0, | 366 0, |
| 367 GL_RGBA, | 367 GL_RGBA, |
| 368 64, | 368 64, |
| 369 64, | 369 64, |
| 370 1, | 370 1, |
| 371 0, | 371 0, |
| 372 GL_RGBA, | 372 GL_RGBA, |
| 373 GL_UNSIGNED_BYTE, | 373 GL_UNSIGNED_BYTE, |
| 374 true); | 374 true); |
| 375 // ...and immediately delete the texture which should save the changes. | 375 // ...and immediately delete the texture which should save the changes. |
| 376 SetupUpdateTexParamExpectations( | 376 SetupUpdateTexParamExpectations( |
| 377 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); | 377 kNewTextureId, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); |
| 378 DestroyTexture(texture); | 378 DestroyTexture(texture); |
| 379 | 379 |
| 380 // Should be still around since there is a ref from manager2 | 380 // Should be still around since there is a ref from manager2 |
| 381 EXPECT_EQ(new_texture, manager2_->ConsumeTexture(GL_TEXTURE_2D, name)); | 381 EXPECT_EQ(new_texture, manager2_->ConsumeTexture(GL_TEXTURE_2D, name)); |
| 382 | 382 |
| 383 // The last change to the texture should be visible without a sync point (i.e. | 383 // The last change to the texture should be visible without a sync point (i.e. |
| 384 // push). | 384 // push). |
| 385 manager2_->PullTextureUpdates(); | 385 manager2_->PullTextureUpdates(0); |
| 386 new_texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height); | 386 new_texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height); |
| 387 EXPECT_EQ(64, width); | 387 EXPECT_EQ(64, width); |
| 388 EXPECT_EQ(64, height); | 388 EXPECT_EQ(64, height); |
| 389 | 389 |
| 390 DestroyTexture(new_texture); | 390 DestroyTexture(new_texture); |
| 391 EXPECT_EQ(NULL, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); | 391 EXPECT_EQ(NULL, manager_->ConsumeTexture(GL_TEXTURE_2D, name)); |
| 392 EXPECT_EQ(NULL, manager2_->ConsumeTexture(GL_TEXTURE_2D, name)); | 392 EXPECT_EQ(NULL, manager2_->ConsumeTexture(GL_TEXTURE_2D, name)); |
| 393 } | 393 } |
| 394 | 394 |
| 395 // Makes sure changes are correctly published even when updates are | 395 // 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 | 396 // pushed in both directions, i.e. makes sure we don't clobber a shared |
| 397 // texture definition with an older version. | 397 // texture definition with an older version. |
| 398 TEST_F(MailboxManagerSyncTest, ProduceConsumeBidirectional) { | 398 TEST_F(MailboxManagerSyncTest, ProduceConsumeBidirectional) { |
| 399 const GLuint kNewTextureId1 = 1234; | 399 const GLuint kNewTextureId1 = 1234; |
| 400 const GLuint kNewTextureId2 = 4321; | 400 const GLuint kNewTextureId2 = 4321; |
| 401 | 401 |
| 402 Texture* texture1 = DefineTexture(); | 402 Texture* texture1 = DefineTexture(); |
| 403 Mailbox name1 = Mailbox::Generate(); | 403 Mailbox name1 = Mailbox::Generate(); |
| 404 Texture* texture2 = DefineTexture(); | 404 Texture* texture2 = DefineTexture(); |
| 405 Mailbox name2 = Mailbox::Generate(); | 405 Mailbox name2 = Mailbox::Generate(); |
| 406 Texture* new_texture1 = NULL; | 406 Texture* new_texture1 = NULL; |
| 407 Texture* new_texture2 = NULL; | 407 Texture* new_texture2 = NULL; |
| 408 | 408 |
| 409 manager_->ProduceTexture(GL_TEXTURE_2D, name1, texture1); | 409 manager_->ProduceTexture(GL_TEXTURE_2D, name1, texture1); |
| 410 manager2_->ProduceTexture(GL_TEXTURE_2D, name2, texture2); | 410 manager2_->ProduceTexture(GL_TEXTURE_2D, name2, texture2); |
| 411 | 411 |
| 412 // Make visible. | 412 // Make visible. |
| 413 manager_->PushTextureUpdates(); | 413 manager_->PushTextureUpdates(0); |
| 414 manager2_->PushTextureUpdates(); | 414 manager2_->PushTextureUpdates(0); |
| 415 | 415 |
| 416 // Create textures in the other manager instances for texture1 and texture2, | 416 // Create textures in the other manager instances for texture1 and texture2, |
| 417 // respectively to create a real sharing scenario. Otherwise, there would | 417 // respectively to create a real sharing scenario. Otherwise, there would |
| 418 // never be conflicting updates/pushes. | 418 // never be conflicting updates/pushes. |
| 419 { | 419 { |
| 420 InSequence sequence; | 420 InSequence sequence; |
| 421 EXPECT_CALL(*gl_, GenTextures(1, _)) | 421 EXPECT_CALL(*gl_, GenTextures(1, _)) |
| 422 .WillOnce(SetArgPointee<1>(kNewTextureId1)); | 422 .WillOnce(SetArgPointee<1>(kNewTextureId1)); |
| 423 SetupUpdateTexParamExpectations( | 423 SetupUpdateTexParamExpectations( |
| 424 kNewTextureId1, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); | 424 kNewTextureId1, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); |
| 425 new_texture1 = manager2_->ConsumeTexture(GL_TEXTURE_2D, name1); | 425 new_texture1 = manager2_->ConsumeTexture(GL_TEXTURE_2D, name1); |
| 426 EXPECT_CALL(*gl_, GenTextures(1, _)) | 426 EXPECT_CALL(*gl_, GenTextures(1, _)) |
| 427 .WillOnce(SetArgPointee<1>(kNewTextureId2)); | 427 .WillOnce(SetArgPointee<1>(kNewTextureId2)); |
| 428 SetupUpdateTexParamExpectations( | 428 SetupUpdateTexParamExpectations( |
| 429 kNewTextureId2, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); | 429 kNewTextureId2, GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT); |
| 430 new_texture2 = manager_->ConsumeTexture(GL_TEXTURE_2D, name2); | 430 new_texture2 = manager_->ConsumeTexture(GL_TEXTURE_2D, name2); |
| 431 } | 431 } |
| 432 EXPECT_EQ(kNewTextureId1, new_texture1->service_id()); | 432 EXPECT_EQ(kNewTextureId1, new_texture1->service_id()); |
| 433 EXPECT_EQ(kNewTextureId2, new_texture2->service_id()); | 433 EXPECT_EQ(kNewTextureId2, new_texture2->service_id()); |
| 434 | 434 |
| 435 // Make a change to texture1 | 435 // Make a change to texture1 |
| 436 DCHECK_EQ(static_cast<GLuint>(GL_LINEAR), texture1->min_filter()); | 436 DCHECK_EQ(static_cast<GLuint>(GL_LINEAR), texture1->min_filter()); |
| 437 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), | 437 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), |
| 438 SetParameter(texture1, GL_TEXTURE_MIN_FILTER, GL_NEAREST)); | 438 SetParameter(texture1, GL_TEXTURE_MIN_FILTER, GL_NEAREST)); |
| 439 | 439 |
| 440 // Make sure this does not clobber it with the previous version we pushed. | 440 // Make sure this does not clobber it with the previous version we pushed. |
| 441 manager_->PullTextureUpdates(); | 441 manager_->PullTextureUpdates(0); |
| 442 | 442 |
| 443 // Make a change to texture2 | 443 // Make a change to texture2 |
| 444 DCHECK_EQ(static_cast<GLuint>(GL_LINEAR), texture2->mag_filter()); | 444 DCHECK_EQ(static_cast<GLuint>(GL_LINEAR), texture2->mag_filter()); |
| 445 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), | 445 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), |
| 446 SetParameter(texture2, GL_TEXTURE_MAG_FILTER, GL_NEAREST)); | 446 SetParameter(texture2, GL_TEXTURE_MAG_FILTER, GL_NEAREST)); |
| 447 | 447 |
| 448 Mock::VerifyAndClearExpectations(gl_.get()); | 448 Mock::VerifyAndClearExpectations(gl_.get()); |
| 449 | 449 |
| 450 // Synchronize in both directions | 450 // Synchronize in both directions |
| 451 manager_->PushTextureUpdates(); | 451 manager_->PushTextureUpdates(0); |
| 452 manager2_->PushTextureUpdates(); | 452 manager2_->PushTextureUpdates(0); |
| 453 // manager1 should see the change to texture2 mag_filter being applied. | 453 // manager1 should see the change to texture2 mag_filter being applied. |
| 454 SetupUpdateTexParamExpectations( | 454 SetupUpdateTexParamExpectations( |
| 455 new_texture2->service_id(), GL_LINEAR, GL_NEAREST, GL_REPEAT, GL_REPEAT); | 455 new_texture2->service_id(), GL_LINEAR, GL_NEAREST, GL_REPEAT, GL_REPEAT); |
| 456 manager_->PullTextureUpdates(); | 456 manager_->PullTextureUpdates(0); |
| 457 // manager2 should see the change to texture1 min_filter being applied. | 457 // manager2 should see the change to texture1 min_filter being applied. |
| 458 SetupUpdateTexParamExpectations( | 458 SetupUpdateTexParamExpectations( |
| 459 new_texture1->service_id(), GL_NEAREST, GL_LINEAR, GL_REPEAT, GL_REPEAT); | 459 new_texture1->service_id(), GL_NEAREST, GL_LINEAR, GL_REPEAT, GL_REPEAT); |
| 460 manager2_->PullTextureUpdates(); | 460 manager2_->PullTextureUpdates(0); |
| 461 | 461 |
| 462 DestroyTexture(texture1); | 462 DestroyTexture(texture1); |
| 463 DestroyTexture(texture2); | 463 DestroyTexture(texture2); |
| 464 DestroyTexture(new_texture1); | 464 DestroyTexture(new_texture1); |
| 465 DestroyTexture(new_texture2); | 465 DestroyTexture(new_texture2); |
| 466 } | 466 } |
| 467 | 467 |
| 468 // TODO: different texture into same mailbox | 468 // TODO: different texture into same mailbox |
| 469 | 469 |
| 470 // TODO: same texture, multiple mailboxes | 470 // TODO: same texture, multiple mailboxes |
| 471 | 471 |
| 472 // TODO: Produce incomplete texture | 472 // TODO: Produce incomplete texture |
| 473 | 473 |
| 474 // TODO: Texture::level_infos_[][].size() | 474 // TODO: Texture::level_infos_[][].size() |
| 475 | 475 |
| 476 // TODO: unsupported targets and formats | 476 // TODO: unsupported targets and formats |
| 477 | 477 |
| 478 } // namespace gles2 | 478 } // namespace gles2 |
| 479 } // namespace gpu | 479 } // namespace gpu |
| OLD | NEW |