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

Side by Side Diff: cc/resources/resource_provider_unittest.cc

Issue 951673002: Revert "Pull chromium at 2c3ffb2355a27c32f45e508ef861416b820c823b" (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « cc/resources/resource_provider.cc ('k') | cc/resources/scoped_resource.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/resources/resource_provider.h" 5 #include "cc/resources/resource_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 10
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 }; 347 };
348 348
349 void GetResourcePixels(ResourceProvider* resource_provider, 349 void GetResourcePixels(ResourceProvider* resource_provider,
350 ResourceProviderContext* context, 350 ResourceProviderContext* context,
351 ResourceProvider::ResourceId id, 351 ResourceProvider::ResourceId id,
352 const gfx::Size& size, 352 const gfx::Size& size,
353 ResourceFormat format, 353 ResourceFormat format,
354 uint8_t* pixels) { 354 uint8_t* pixels) {
355 resource_provider->WaitSyncPointIfNeeded(id); 355 resource_provider->WaitSyncPointIfNeeded(id);
356 switch (resource_provider->default_resource_type()) { 356 switch (resource_provider->default_resource_type()) {
357 case ResourceProvider::RESOURCE_TYPE_GL_TEXTURE: { 357 case ResourceProvider::GLTexture: {
358 ResourceProvider::ScopedReadLockGL lock_gl(resource_provider, id); 358 ResourceProvider::ScopedReadLockGL lock_gl(resource_provider, id);
359 ASSERT_NE(0U, lock_gl.texture_id()); 359 ASSERT_NE(0U, lock_gl.texture_id());
360 context->bindTexture(GL_TEXTURE_2D, lock_gl.texture_id()); 360 context->bindTexture(GL_TEXTURE_2D, lock_gl.texture_id());
361 context->GetPixels(size, format, pixels); 361 context->GetPixels(size, format, pixels);
362 break; 362 break;
363 } 363 }
364 case ResourceProvider::RESOURCE_TYPE_BITMAP: { 364 case ResourceProvider::Bitmap: {
365 ResourceProvider::ScopedReadLockSoftware lock_software(resource_provider, 365 ResourceProvider::ScopedReadLockSoftware lock_software(resource_provider,
366 id); 366 id);
367 memcpy(pixels, 367 memcpy(pixels,
368 lock_software.sk_bitmap()->getPixels(), 368 lock_software.sk_bitmap()->getPixels(),
369 lock_software.sk_bitmap()->getSize()); 369 lock_software.sk_bitmap()->getSize());
370 break; 370 break;
371 } 371 }
372 case ResourceProvider::RESOURCE_TYPE_INVALID: 372 case ResourceProvider::InvalidType:
373 NOTREACHED(); 373 NOTREACHED();
374 break; 374 break;
375 } 375 }
376 } 376 }
377 377
378 class ResourceProviderTest 378 class ResourceProviderTest
379 : public testing::TestWithParam<ResourceProvider::ResourceType> { 379 : public testing::TestWithParam<ResourceProvider::ResourceType> {
380 public: 380 public:
381 ResourceProviderTest() 381 ResourceProviderTest()
382 : shared_data_(ContextSharedData::Create()), 382 : shared_data_(ContextSharedData::Create()),
383 context3d_(NULL), 383 context3d_(NULL),
384 child_context_(NULL), 384 child_context_(NULL),
385 main_thread_task_runner_(BlockingTaskRunner::Create(NULL)) { 385 main_thread_task_runner_(BlockingTaskRunner::Create(NULL)) {
386 switch (GetParam()) { 386 switch (GetParam()) {
387 case ResourceProvider::RESOURCE_TYPE_GL_TEXTURE: { 387 case ResourceProvider::GLTexture: {
388 scoped_ptr<ResourceProviderContext> context3d( 388 scoped_ptr<ResourceProviderContext> context3d(
389 ResourceProviderContext::Create(shared_data_.get())); 389 ResourceProviderContext::Create(shared_data_.get()));
390 context3d_ = context3d.get(); 390 context3d_ = context3d.get();
391 391
392 scoped_refptr<TestContextProvider> context_provider = 392 scoped_refptr<TestContextProvider> context_provider =
393 TestContextProvider::Create(context3d.Pass()); 393 TestContextProvider::Create(context3d.Pass());
394 394
395 output_surface_ = FakeOutputSurface::Create3d(context_provider); 395 output_surface_ = FakeOutputSurface::Create3d(context_provider);
396 396
397 scoped_ptr<ResourceProviderContext> child_context_owned = 397 scoped_ptr<ResourceProviderContext> child_context_owned =
398 ResourceProviderContext::Create(shared_data_.get()); 398 ResourceProviderContext::Create(shared_data_.get());
399 child_context_ = child_context_owned.get(); 399 child_context_ = child_context_owned.get();
400 child_output_surface_ = 400 child_output_surface_ =
401 FakeOutputSurface::Create3d(child_context_owned.Pass()); 401 FakeOutputSurface::Create3d(child_context_owned.Pass());
402 break; 402 break;
403 } 403 }
404 case ResourceProvider::RESOURCE_TYPE_BITMAP: 404 case ResourceProvider::Bitmap:
405 output_surface_ = FakeOutputSurface::CreateSoftware( 405 output_surface_ = FakeOutputSurface::CreateSoftware(
406 make_scoped_ptr(new SoftwareOutputDevice)); 406 make_scoped_ptr(new SoftwareOutputDevice));
407 child_output_surface_ = FakeOutputSurface::CreateSoftware( 407 child_output_surface_ = FakeOutputSurface::CreateSoftware(
408 make_scoped_ptr(new SoftwareOutputDevice)); 408 make_scoped_ptr(new SoftwareOutputDevice));
409 break; 409 break;
410 case ResourceProvider::RESOURCE_TYPE_INVALID: 410 case ResourceProvider::InvalidType:
411 NOTREACHED(); 411 NOTREACHED();
412 break; 412 break;
413 } 413 }
414 CHECK(output_surface_->BindToClient(&output_surface_client_)); 414 CHECK(output_surface_->BindToClient(&output_surface_client_));
415 CHECK(child_output_surface_->BindToClient(&child_output_surface_client_)); 415 CHECK(child_output_surface_->BindToClient(&child_output_surface_client_));
416 416
417 shared_bitmap_manager_.reset(new TestSharedBitmapManager); 417 shared_bitmap_manager_.reset(new TestSharedBitmapManager);
418 gpu_memory_buffer_manager_.reset(new TestGpuMemoryBufferManager); 418 gpu_memory_buffer_manager_.reset(new TestGpuMemoryBufferManager);
419 419
420 resource_provider_ = 420 resource_provider_ =
(...skipping 30 matching lines...) Expand all
451 ResourceProvider::ScopedSamplerGL sampler( 451 ResourceProvider::ScopedSamplerGL sampler(
452 resource_provider, id, GL_TEXTURE_2D, filter); 452 resource_provider, id, GL_TEXTURE_2D, filter);
453 } 453 }
454 454
455 ResourceProviderContext* context() { return context3d_; } 455 ResourceProviderContext* context() { return context3d_; }
456 456
457 ResourceProvider::ResourceId CreateChildMailbox(uint32* release_sync_point, 457 ResourceProvider::ResourceId CreateChildMailbox(uint32* release_sync_point,
458 bool* lost_resource, 458 bool* lost_resource,
459 bool* release_called, 459 bool* release_called,
460 uint32* sync_point) { 460 uint32* sync_point) {
461 if (GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) { 461 if (GetParam() == ResourceProvider::GLTexture) {
462 unsigned texture = child_context_->createTexture(); 462 unsigned texture = child_context_->createTexture();
463 gpu::Mailbox gpu_mailbox; 463 gpu::Mailbox gpu_mailbox;
464 child_context_->bindTexture(GL_TEXTURE_2D, texture); 464 child_context_->bindTexture(GL_TEXTURE_2D, texture);
465 child_context_->genMailboxCHROMIUM(gpu_mailbox.name); 465 child_context_->genMailboxCHROMIUM(gpu_mailbox.name);
466 child_context_->produceTextureCHROMIUM(GL_TEXTURE_2D, gpu_mailbox.name); 466 child_context_->produceTextureCHROMIUM(GL_TEXTURE_2D, gpu_mailbox.name);
467 *sync_point = child_context_->insertSyncPoint(); 467 *sync_point = child_context_->insertSyncPoint();
468 EXPECT_LT(0u, *sync_point); 468 EXPECT_LT(0u, *sync_point);
469 469
470 scoped_ptr<SharedBitmap> shared_bitmap; 470 scoped_ptr<SharedBitmap> shared_bitmap;
471 scoped_ptr<SingleReleaseCallbackImpl> callback = 471 scoped_ptr<SingleReleaseCallbackImpl> callback =
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 ResourceProvider* resource_provider, 509 ResourceProvider* resource_provider,
510 ResourceProviderContext* context) { 510 ResourceProviderContext* context) {
511 DCHECK_EQ(expected_default_type, resource_provider->default_resource_type()); 511 DCHECK_EQ(expected_default_type, resource_provider->default_resource_type());
512 512
513 gfx::Size size(1, 1); 513 gfx::Size size(1, 1);
514 ResourceFormat format = RGBA_8888; 514 ResourceFormat format = RGBA_8888;
515 size_t pixel_size = TextureSizeBytes(size, format); 515 size_t pixel_size = TextureSizeBytes(size, format);
516 ASSERT_EQ(4U, pixel_size); 516 ASSERT_EQ(4U, pixel_size);
517 517
518 ResourceProvider::ResourceId id = resource_provider->CreateResource( 518 ResourceProvider::ResourceId id = resource_provider->CreateResource(
519 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); 519 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
520 EXPECT_EQ(1, static_cast<int>(resource_provider->num_resources())); 520 EXPECT_EQ(1, static_cast<int>(resource_provider->num_resources()));
521 if (expected_default_type == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 521 if (expected_default_type == ResourceProvider::GLTexture)
522 EXPECT_EQ(0u, context->NumTextures()); 522 EXPECT_EQ(0u, context->NumTextures());
523 523
524 uint8_t data[4] = { 1, 2, 3, 4 }; 524 uint8_t data[4] = { 1, 2, 3, 4 };
525 resource_provider->CopyToResource(id, data, size); 525 gfx::Rect rect(size);
526 if (expected_default_type == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 526 resource_provider->SetPixels(id, data, rect, rect, gfx::Vector2d());
527 if (expected_default_type == ResourceProvider::GLTexture)
527 EXPECT_EQ(1u, context->NumTextures()); 528 EXPECT_EQ(1u, context->NumTextures());
528 529
529 uint8_t result[4] = { 0 }; 530 uint8_t result[4] = { 0 };
530 GetResourcePixels(resource_provider, context, id, size, format, result); 531 GetResourcePixels(resource_provider, context, id, size, format, result);
531 EXPECT_EQ(0, memcmp(data, result, pixel_size)); 532 EXPECT_EQ(0, memcmp(data, result, pixel_size));
532 533
533 resource_provider->DeleteResource(id); 534 resource_provider->DeleteResource(id);
534 EXPECT_EQ(0, static_cast<int>(resource_provider->num_resources())); 535 EXPECT_EQ(0, static_cast<int>(resource_provider->num_resources()));
535 if (expected_default_type == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 536 if (expected_default_type == ResourceProvider::GLTexture)
536 EXPECT_EQ(0u, context->NumTextures()); 537 EXPECT_EQ(0u, context->NumTextures());
537 } 538 }
538 539
539 TEST_P(ResourceProviderTest, Basic) { 540 TEST_P(ResourceProviderTest, Basic) {
540 CheckCreateResource(GetParam(), resource_provider_.get(), context()); 541 CheckCreateResource(GetParam(), resource_provider_.get(), context());
541 } 542 }
542 543
543 TEST_P(ResourceProviderTest, Upload) { 544 TEST_P(ResourceProviderTest, Upload) {
544 gfx::Size size(2, 2); 545 gfx::Size size(2, 2);
545 ResourceFormat format = RGBA_8888; 546 ResourceFormat format = RGBA_8888;
546 size_t pixel_size = TextureSizeBytes(size, format); 547 size_t pixel_size = TextureSizeBytes(size, format);
547 ASSERT_EQ(16U, pixel_size); 548 ASSERT_EQ(16U, pixel_size);
548 549
549 ResourceProvider::ResourceId id = resource_provider_->CreateResource( 550 ResourceProvider::ResourceId id = resource_provider_->CreateResource(
550 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); 551 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
551 552
552 uint8_t image[16] = { 0 }; 553 uint8_t image[16] = { 0 };
553 gfx::Rect image_rect(size); 554 gfx::Rect image_rect(size);
554 resource_provider_->SetPixels( 555 resource_provider_->SetPixels(
555 id, image, image_rect, image_rect, gfx::Vector2d()); 556 id, image, image_rect, image_rect, gfx::Vector2d());
556 557
557 for (uint8_t i = 0; i < pixel_size; ++i) 558 for (uint8_t i = 0; i < pixel_size; ++i)
558 image[i] = i; 559 image[i] = i;
559 560
560 uint8_t result[16] = { 0 }; 561 uint8_t result[16] = { 0 };
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 601
601 uint8_t expected[16] = { 0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3 }; 602 uint8_t expected[16] = { 0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3 };
602 GetResourcePixels( 603 GetResourcePixels(
603 resource_provider_.get(), context(), id, size, format, result); 604 resource_provider_.get(), context(), id, size, format, result);
604 EXPECT_EQ(0, memcmp(expected, result, pixel_size)); 605 EXPECT_EQ(0, memcmp(expected, result, pixel_size));
605 } 606 }
606 607
607 resource_provider_->DeleteResource(id); 608 resource_provider_->DeleteResource(id);
608 } 609 }
609 610
610 TEST_P(ResourceProviderTest, SimpleUpload) {
611 gfx::Size size(2, 2);
612 ResourceFormat format = RGBA_8888;
613 size_t pixel_size = TextureSizeBytes(size, format);
614 ASSERT_EQ(16U, pixel_size);
615
616 ResourceProvider::ResourceId id = resource_provider_->CreateResource(
617 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format);
618
619 uint8_t image[16] = {0};
620 resource_provider_->CopyToResource(id, image, size);
621 {
622 uint8_t result[16] = {0};
623 uint8_t expected[16] = {0};
624 GetResourcePixels(resource_provider_.get(), context(), id, size, format,
625 result);
626 EXPECT_EQ(0, memcmp(expected, result, pixel_size));
627 }
628
629 for (uint8_t i = 0; i < pixel_size; ++i)
630 image[i] = i;
631 resource_provider_->CopyToResource(id, image, size);
632 {
633 uint8_t result[16] = {0};
634 uint8_t expected[16] = {
635 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
636 GetResourcePixels(resource_provider_.get(), context(), id, size, format,
637 result);
638 EXPECT_EQ(0, memcmp(expected, result, pixel_size));
639 }
640 }
641
642 TEST_P(ResourceProviderTest, TransferGLResources) { 611 TEST_P(ResourceProviderTest, TransferGLResources) {
643 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 612 if (GetParam() != ResourceProvider::GLTexture)
644 return; 613 return;
645 gfx::Size size(1, 1); 614 gfx::Size size(1, 1);
646 ResourceFormat format = RGBA_8888; 615 ResourceFormat format = RGBA_8888;
647 size_t pixel_size = TextureSizeBytes(size, format); 616 size_t pixel_size = TextureSizeBytes(size, format);
648 ASSERT_EQ(4U, pixel_size); 617 ASSERT_EQ(4U, pixel_size);
649 618
650 ResourceProvider::ResourceId id1 = child_resource_provider_->CreateResource( 619 ResourceProvider::ResourceId id1 = child_resource_provider_->CreateResource(
651 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); 620 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
652 uint8_t data1[4] = { 1, 2, 3, 4 }; 621 uint8_t data1[4] = { 1, 2, 3, 4 };
653 child_resource_provider_->CopyToResource(id1, data1, size); 622 gfx::Rect rect(size);
623 child_resource_provider_->SetPixels(id1, data1, rect, rect, gfx::Vector2d());
654 624
655 ResourceProvider::ResourceId id2 = child_resource_provider_->CreateResource( 625 ResourceProvider::ResourceId id2 = child_resource_provider_->CreateResource(
656 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); 626 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
657 uint8_t data2[4] = { 5, 5, 5, 5 }; 627 uint8_t data2[4] = { 5, 5, 5, 5 };
658 child_resource_provider_->CopyToResource(id2, data2, size); 628 child_resource_provider_->SetPixels(id2, data2, rect, rect, gfx::Vector2d());
659 629
660 ResourceProvider::ResourceId id3 = child_resource_provider_->CreateResource( 630 ResourceProvider::ResourceId id3 = child_resource_provider_->CreateResource(
661 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); 631 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
662 { 632 {
663 ResourceProvider::ScopedWriteLockGpuMemoryBuffer lock( 633 ResourceProvider::ScopedWriteLockGpuMemoryBuffer lock(
664 child_resource_provider_.get(), id3); 634 child_resource_provider_.get(), id3);
665 EXPECT_TRUE(!!lock.GetGpuMemoryBuffer()); 635 EXPECT_TRUE(!!lock.GetGpuMemoryBuffer());
666 } 636 }
667 637
668 GLuint external_texture_id = child_context_->createExternalTexture(); 638 GLuint external_texture_id = child_context_->createExternalTexture();
669 child_context_->bindTexture(GL_TEXTURE_EXTERNAL_OES, external_texture_id); 639 child_context_->bindTexture(GL_TEXTURE_EXTERNAL_OES, external_texture_id);
670 640
671 gpu::Mailbox external_mailbox; 641 gpu::Mailbox external_mailbox;
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 EXPECT_NE(0u, returned_to_child[1].sync_point); 848 EXPECT_NE(0u, returned_to_child[1].sync_point);
879 EXPECT_NE(0u, returned_to_child[2].sync_point); 849 EXPECT_NE(0u, returned_to_child[2].sync_point);
880 EXPECT_NE(0u, returned_to_child[3].sync_point); 850 EXPECT_NE(0u, returned_to_child[3].sync_point);
881 EXPECT_FALSE(returned_to_child[0].lost); 851 EXPECT_FALSE(returned_to_child[0].lost);
882 EXPECT_FALSE(returned_to_child[1].lost); 852 EXPECT_FALSE(returned_to_child[1].lost);
883 EXPECT_FALSE(returned_to_child[2].lost); 853 EXPECT_FALSE(returned_to_child[2].lost);
884 EXPECT_FALSE(returned_to_child[3].lost); 854 EXPECT_FALSE(returned_to_child[3].lost);
885 } 855 }
886 856
887 TEST_P(ResourceProviderTest, ReadLockCountStopsReturnToChildOrDelete) { 857 TEST_P(ResourceProviderTest, ReadLockCountStopsReturnToChildOrDelete) {
888 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 858 if (GetParam() != ResourceProvider::GLTexture)
889 return; 859 return;
890 gfx::Size size(1, 1); 860 gfx::Size size(1, 1);
891 ResourceFormat format = RGBA_8888; 861 ResourceFormat format = RGBA_8888;
892 862
893 ResourceProvider::ResourceId id1 = child_resource_provider_->CreateResource( 863 ResourceProvider::ResourceId id1 = child_resource_provider_->CreateResource(
894 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); 864 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
895 uint8_t data1[4] = {1, 2, 3, 4}; 865 uint8_t data1[4] = {1, 2, 3, 4};
896 child_resource_provider_->CopyToResource(id1, data1, size); 866 gfx::Rect rect(size);
867 child_resource_provider_->SetPixels(id1, data1, rect, rect, gfx::Vector2d());
897 868
898 ReturnedResourceArray returned_to_child; 869 ReturnedResourceArray returned_to_child;
899 int child_id = 870 int child_id =
900 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); 871 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child));
901 { 872 {
902 // Transfer some resources to the parent. 873 // Transfer some resources to the parent.
903 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 874 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
904 resource_ids_to_transfer.push_back(id1); 875 resource_ids_to_transfer.push_back(id1);
905 TransferableResourceArray list; 876 TransferableResourceArray list;
906 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, 877 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer,
(...skipping 23 matching lines...) Expand all
930 EXPECT_EQ(1u, child_resource_provider_->num_resources()); 901 EXPECT_EQ(1u, child_resource_provider_->num_resources());
931 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); 902 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1));
932 } 903 }
933 904
934 EXPECT_EQ(0u, child_resource_provider_->num_resources()); 905 EXPECT_EQ(0u, child_resource_provider_->num_resources());
935 resource_provider_->DestroyChild(child_id); 906 resource_provider_->DestroyChild(child_id);
936 } 907 }
937 908
938 TEST_P(ResourceProviderTest, AllowOverlayTransfersToParent) { 909 TEST_P(ResourceProviderTest, AllowOverlayTransfersToParent) {
939 // Overlays only supported on the GL path. 910 // Overlays only supported on the GL path.
940 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 911 if (GetParam() != ResourceProvider::GLTexture)
941 return; 912 return;
942 913
943 uint32 sync_point = 0; 914 uint32 sync_point = 0;
944 TextureMailbox mailbox(gpu::Mailbox::Generate(), GL_TEXTURE_2D, sync_point); 915 TextureMailbox mailbox(gpu::Mailbox::Generate(), GL_TEXTURE_2D, sync_point);
945 mailbox.set_allow_overlay(true); 916 mailbox.set_allow_overlay(true);
946 scoped_ptr<SingleReleaseCallbackImpl> release_callback = 917 scoped_ptr<SingleReleaseCallbackImpl> release_callback =
947 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback)); 918 SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback));
948 ResourceProvider::ResourceId id1 = 919 ResourceProvider::ResourceId id1 =
949 child_resource_provider_->CreateResourceFromTextureMailbox( 920 child_resource_provider_->CreateResourceFromTextureMailbox(
950 mailbox, release_callback.Pass()); 921 mailbox, release_callback.Pass());
(...skipping 29 matching lines...) Expand all
980 child_resource_provider_->ReceiveReturnsFromParent(returned_to_child); 951 child_resource_provider_->ReceiveReturnsFromParent(returned_to_child);
981 952
982 child_resource_provider_->DeleteResource(id1); 953 child_resource_provider_->DeleteResource(id1);
983 child_resource_provider_->DeleteResource(id2); 954 child_resource_provider_->DeleteResource(id2);
984 EXPECT_EQ(0u, child_resource_provider_->num_resources()); 955 EXPECT_EQ(0u, child_resource_provider_->num_resources());
985 956
986 resource_provider_->DestroyChild(child_id); 957 resource_provider_->DestroyChild(child_id);
987 } 958 }
988 959
989 TEST_P(ResourceProviderTest, TransferSoftwareResources) { 960 TEST_P(ResourceProviderTest, TransferSoftwareResources) {
990 if (GetParam() != ResourceProvider::RESOURCE_TYPE_BITMAP) 961 if (GetParam() != ResourceProvider::Bitmap)
991 return; 962 return;
992 963
993 gfx::Size size(1, 1); 964 gfx::Size size(1, 1);
994 ResourceFormat format = RGBA_8888; 965 ResourceFormat format = RGBA_8888;
995 size_t pixel_size = TextureSizeBytes(size, format); 966 size_t pixel_size = TextureSizeBytes(size, format);
996 ASSERT_EQ(4U, pixel_size); 967 ASSERT_EQ(4U, pixel_size);
997 968
998 ResourceProvider::ResourceId id1 = child_resource_provider_->CreateResource( 969 ResourceProvider::ResourceId id1 = child_resource_provider_->CreateResource(
999 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); 970 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
1000 uint8_t data1[4] = { 1, 2, 3, 4 }; 971 uint8_t data1[4] = { 1, 2, 3, 4 };
1001 child_resource_provider_->CopyToResource(id1, data1, size); 972 gfx::Rect rect(size);
973 child_resource_provider_->SetPixels(id1, data1, rect, rect, gfx::Vector2d());
1002 974
1003 ResourceProvider::ResourceId id2 = child_resource_provider_->CreateResource( 975 ResourceProvider::ResourceId id2 = child_resource_provider_->CreateResource(
1004 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); 976 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
1005 uint8_t data2[4] = { 5, 5, 5, 5 }; 977 uint8_t data2[4] = { 5, 5, 5, 5 };
1006 child_resource_provider_->CopyToResource(id2, data2, size); 978 child_resource_provider_->SetPixels(id2, data2, rect, rect, gfx::Vector2d());
1007 979
1008 scoped_ptr<SharedBitmap> shared_bitmap(CreateAndFillSharedBitmap( 980 scoped_ptr<SharedBitmap> shared_bitmap(CreateAndFillSharedBitmap(
1009 shared_bitmap_manager_.get(), gfx::Size(1, 1), 0)); 981 shared_bitmap_manager_.get(), gfx::Size(1, 1), 0));
1010 SharedBitmap* shared_bitmap_ptr = shared_bitmap.get(); 982 SharedBitmap* shared_bitmap_ptr = shared_bitmap.get();
1011 ResourceProvider::ResourceId id3 = 983 ResourceProvider::ResourceId id3 =
1012 child_resource_provider_->CreateResourceFromTextureMailbox( 984 child_resource_provider_->CreateResourceFromTextureMailbox(
1013 TextureMailbox(shared_bitmap_ptr, gfx::Size(1, 1)), 985 TextureMailbox(shared_bitmap_ptr, gfx::Size(1, 1)),
1014 SingleReleaseCallbackImpl::Create(base::Bind( 986 SingleReleaseCallbackImpl::Create(base::Bind(
1015 &SharedBitmapReleaseCallback, base::Passed(&shared_bitmap)))); 987 &SharedBitmapReleaseCallback, base::Passed(&shared_bitmap))));
1016 988
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 std::set<ResourceProvider::ResourceId> returned_ids; 1136 std::set<ResourceProvider::ResourceId> returned_ids;
1165 for (unsigned i = 0; i < 3; i++) 1137 for (unsigned i = 0; i < 3; i++)
1166 returned_ids.insert(returned_to_child[i].id); 1138 returned_ids.insert(returned_to_child[i].id);
1167 EXPECT_EQ(expected_ids, returned_ids); 1139 EXPECT_EQ(expected_ids, returned_ids);
1168 EXPECT_FALSE(returned_to_child[0].lost); 1140 EXPECT_FALSE(returned_to_child[0].lost);
1169 EXPECT_FALSE(returned_to_child[1].lost); 1141 EXPECT_FALSE(returned_to_child[1].lost);
1170 EXPECT_FALSE(returned_to_child[2].lost); 1142 EXPECT_FALSE(returned_to_child[2].lost);
1171 } 1143 }
1172 1144
1173 TEST_P(ResourceProviderTest, TransferGLToSoftware) { 1145 TEST_P(ResourceProviderTest, TransferGLToSoftware) {
1174 if (GetParam() != ResourceProvider::RESOURCE_TYPE_BITMAP) 1146 if (GetParam() != ResourceProvider::Bitmap)
1175 return; 1147 return;
1176 1148
1177 scoped_ptr<ResourceProviderContext> child_context_owned( 1149 scoped_ptr<ResourceProviderContext> child_context_owned(
1178 ResourceProviderContext::Create(shared_data_.get())); 1150 ResourceProviderContext::Create(shared_data_.get()));
1179 1151
1180 FakeOutputSurfaceClient child_output_surface_client; 1152 FakeOutputSurfaceClient child_output_surface_client;
1181 scoped_ptr<OutputSurface> child_output_surface( 1153 scoped_ptr<OutputSurface> child_output_surface(
1182 FakeOutputSurface::Create3d(child_context_owned.Pass())); 1154 FakeOutputSurface::Create3d(child_context_owned.Pass()));
1183 CHECK(child_output_surface->BindToClient(&child_output_surface_client)); 1155 CHECK(child_output_surface->BindToClient(&child_output_surface_client));
1184 1156
1185 scoped_ptr<ResourceProvider> child_resource_provider( 1157 scoped_ptr<ResourceProvider> child_resource_provider(
1186 ResourceProvider::Create(child_output_surface.get(), 1158 ResourceProvider::Create(child_output_surface.get(),
1187 shared_bitmap_manager_.get(), 1159 shared_bitmap_manager_.get(),
1188 gpu_memory_buffer_manager_.get(), 1160 gpu_memory_buffer_manager_.get(),
1189 NULL, 1161 NULL,
1190 0, 1162 0,
1191 false, 1163 false,
1192 1)); 1164 1));
1193 1165
1194 gfx::Size size(1, 1); 1166 gfx::Size size(1, 1);
1195 ResourceFormat format = RGBA_8888; 1167 ResourceFormat format = RGBA_8888;
1196 size_t pixel_size = TextureSizeBytes(size, format); 1168 size_t pixel_size = TextureSizeBytes(size, format);
1197 ASSERT_EQ(4U, pixel_size); 1169 ASSERT_EQ(4U, pixel_size);
1198 1170
1199 ResourceProvider::ResourceId id1 = child_resource_provider->CreateResource( 1171 ResourceProvider::ResourceId id1 = child_resource_provider->CreateResource(
1200 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); 1172 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
1201 uint8_t data1[4] = { 1, 2, 3, 4 }; 1173 uint8_t data1[4] = { 1, 2, 3, 4 };
1202 child_resource_provider->CopyToResource(id1, data1, size); 1174 gfx::Rect rect(size);
1175 child_resource_provider->SetPixels(id1, data1, rect, rect, gfx::Vector2d());
1203 1176
1204 ReturnedResourceArray returned_to_child; 1177 ReturnedResourceArray returned_to_child;
1205 int child_id = 1178 int child_id =
1206 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); 1179 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child));
1207 { 1180 {
1208 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 1181 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
1209 resource_ids_to_transfer.push_back(id1); 1182 resource_ids_to_transfer.push_back(id1);
1210 TransferableResourceArray list; 1183 TransferableResourceArray list;
1211 child_resource_provider->PrepareSendToParent(resource_ids_to_transfer, 1184 child_resource_provider->PrepareSendToParent(resource_ids_to_transfer,
1212 &list); 1185 &list);
(...skipping 14 matching lines...) Expand all
1227 EXPECT_EQ(0u, mapped_id1); 1200 EXPECT_EQ(0u, mapped_id1);
1228 1201
1229 resource_provider_->DestroyChild(child_id); 1202 resource_provider_->DestroyChild(child_id);
1230 EXPECT_EQ(0u, resource_provider_->num_resources()); 1203 EXPECT_EQ(0u, resource_provider_->num_resources());
1231 1204
1232 ASSERT_EQ(1u, returned_to_child.size()); 1205 ASSERT_EQ(1u, returned_to_child.size());
1233 EXPECT_FALSE(returned_to_child[0].lost); 1206 EXPECT_FALSE(returned_to_child[0].lost);
1234 } 1207 }
1235 1208
1236 TEST_P(ResourceProviderTest, TransferInvalidSoftware) { 1209 TEST_P(ResourceProviderTest, TransferInvalidSoftware) {
1237 if (GetParam() != ResourceProvider::RESOURCE_TYPE_BITMAP) 1210 if (GetParam() != ResourceProvider::Bitmap)
1238 return; 1211 return;
1239 1212
1240 gfx::Size size(1, 1); 1213 gfx::Size size(1, 1);
1241 ResourceFormat format = RGBA_8888; 1214 ResourceFormat format = RGBA_8888;
1242 size_t pixel_size = TextureSizeBytes(size, format); 1215 size_t pixel_size = TextureSizeBytes(size, format);
1243 ASSERT_EQ(4U, pixel_size); 1216 ASSERT_EQ(4U, pixel_size);
1244 1217
1245 ResourceProvider::ResourceId id1 = child_resource_provider_->CreateResource( 1218 ResourceProvider::ResourceId id1 = child_resource_provider_->CreateResource(
1246 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); 1219 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
1247 uint8_t data1[4] = { 1, 2, 3, 4 }; 1220 uint8_t data1[4] = { 1, 2, 3, 4 };
1248 child_resource_provider_->CopyToResource(id1, data1, size); 1221 gfx::Rect rect(size);
1222 child_resource_provider_->SetPixels(id1, data1, rect, rect, gfx::Vector2d());
1249 1223
1250 ReturnedResourceArray returned_to_child; 1224 ReturnedResourceArray returned_to_child;
1251 int child_id = 1225 int child_id =
1252 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); 1226 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child));
1253 { 1227 {
1254 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 1228 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
1255 resource_ids_to_transfer.push_back(id1); 1229 resource_ids_to_transfer.push_back(id1);
1256 TransferableResourceArray list; 1230 TransferableResourceArray list;
1257 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, 1231 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer,
1258 &list); 1232 &list);
(...skipping 24 matching lines...) Expand all
1283 EXPECT_FALSE(returned_to_child[0].lost); 1257 EXPECT_FALSE(returned_to_child[0].lost);
1284 } 1258 }
1285 1259
1286 TEST_P(ResourceProviderTest, DeleteExportedResources) { 1260 TEST_P(ResourceProviderTest, DeleteExportedResources) {
1287 gfx::Size size(1, 1); 1261 gfx::Size size(1, 1);
1288 ResourceFormat format = RGBA_8888; 1262 ResourceFormat format = RGBA_8888;
1289 size_t pixel_size = TextureSizeBytes(size, format); 1263 size_t pixel_size = TextureSizeBytes(size, format);
1290 ASSERT_EQ(4U, pixel_size); 1264 ASSERT_EQ(4U, pixel_size);
1291 1265
1292 ResourceProvider::ResourceId id1 = child_resource_provider_->CreateResource( 1266 ResourceProvider::ResourceId id1 = child_resource_provider_->CreateResource(
1293 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); 1267 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
1294 uint8_t data1[4] = { 1, 2, 3, 4 }; 1268 uint8_t data1[4] = { 1, 2, 3, 4 };
1295 child_resource_provider_->CopyToResource(id1, data1, size); 1269 gfx::Rect rect(size);
1270 child_resource_provider_->SetPixels(id1, data1, rect, rect, gfx::Vector2d());
1296 1271
1297 ResourceProvider::ResourceId id2 = child_resource_provider_->CreateResource( 1272 ResourceProvider::ResourceId id2 = child_resource_provider_->CreateResource(
1298 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); 1273 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
1299 uint8_t data2[4] = {5, 5, 5, 5}; 1274 uint8_t data2[4] = {5, 5, 5, 5};
1300 child_resource_provider_->CopyToResource(id2, data2, size); 1275 child_resource_provider_->SetPixels(id2, data2, rect, rect, gfx::Vector2d());
1301 1276
1302 ReturnedResourceArray returned_to_child; 1277 ReturnedResourceArray returned_to_child;
1303 int child_id = 1278 int child_id =
1304 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); 1279 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child));
1305 { 1280 {
1306 // Transfer some resources to the parent. 1281 // Transfer some resources to the parent.
1307 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 1282 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
1308 resource_ids_to_transfer.push_back(id1); 1283 resource_ids_to_transfer.push_back(id1);
1309 resource_ids_to_transfer.push_back(id2); 1284 resource_ids_to_transfer.push_back(id2);
1310 TransferableResourceArray list; 1285 TransferableResourceArray list;
1311 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, 1286 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer,
1312 &list); 1287 &list);
1313 ASSERT_EQ(2u, list.size()); 1288 ASSERT_EQ(2u, list.size());
1314 if (GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) { 1289 if (GetParam() == ResourceProvider::GLTexture) {
1315 EXPECT_NE(0u, list[0].mailbox_holder.sync_point); 1290 EXPECT_NE(0u, list[0].mailbox_holder.sync_point);
1316 EXPECT_NE(0u, list[1].mailbox_holder.sync_point); 1291 EXPECT_NE(0u, list[1].mailbox_holder.sync_point);
1317 } 1292 }
1318 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); 1293 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1));
1319 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2)); 1294 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2));
1320 resource_provider_->ReceiveFromChild(child_id, list); 1295 resource_provider_->ReceiveFromChild(child_id, list);
1321 resource_provider_->DeclareUsedResourcesFromChild(child_id, 1296 resource_provider_->DeclareUsedResourcesFromChild(child_id,
1322 resource_ids_to_transfer); 1297 resource_ids_to_transfer);
1323 } 1298 }
1324 1299
1325 EXPECT_EQ(2u, resource_provider_->num_resources()); 1300 EXPECT_EQ(2u, resource_provider_->num_resources());
1326 ResourceProvider::ResourceIdMap resource_map = 1301 ResourceProvider::ResourceIdMap resource_map =
1327 resource_provider_->GetChildToParentMap(child_id); 1302 resource_provider_->GetChildToParentMap(child_id);
1328 ResourceProvider::ResourceId mapped_id1 = resource_map[id1]; 1303 ResourceProvider::ResourceId mapped_id1 = resource_map[id1];
1329 ResourceProvider::ResourceId mapped_id2 = resource_map[id2]; 1304 ResourceProvider::ResourceId mapped_id2 = resource_map[id2];
1330 EXPECT_NE(0u, mapped_id1); 1305 EXPECT_NE(0u, mapped_id1);
1331 EXPECT_NE(0u, mapped_id2); 1306 EXPECT_NE(0u, mapped_id2);
1332 EXPECT_FALSE(resource_provider_->InUseByConsumer(id1)); 1307 EXPECT_FALSE(resource_provider_->InUseByConsumer(id1));
1333 EXPECT_FALSE(resource_provider_->InUseByConsumer(id2)); 1308 EXPECT_FALSE(resource_provider_->InUseByConsumer(id2));
1334 1309
1335 { 1310 {
1336 // The parent transfers the resources to the grandparent. 1311 // The parent transfers the resources to the grandparent.
1337 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 1312 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
1338 resource_ids_to_transfer.push_back(mapped_id1); 1313 resource_ids_to_transfer.push_back(mapped_id1);
1339 resource_ids_to_transfer.push_back(mapped_id2); 1314 resource_ids_to_transfer.push_back(mapped_id2);
1340 TransferableResourceArray list; 1315 TransferableResourceArray list;
1341 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); 1316 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list);
1342 1317
1343 ASSERT_EQ(2u, list.size()); 1318 ASSERT_EQ(2u, list.size());
1344 if (GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) { 1319 if (GetParam() == ResourceProvider::GLTexture) {
1345 EXPECT_NE(0u, list[0].mailbox_holder.sync_point); 1320 EXPECT_NE(0u, list[0].mailbox_holder.sync_point);
1346 EXPECT_NE(0u, list[1].mailbox_holder.sync_point); 1321 EXPECT_NE(0u, list[1].mailbox_holder.sync_point);
1347 } 1322 }
1348 EXPECT_TRUE(resource_provider_->InUseByConsumer(id1)); 1323 EXPECT_TRUE(resource_provider_->InUseByConsumer(id1));
1349 EXPECT_TRUE(resource_provider_->InUseByConsumer(id2)); 1324 EXPECT_TRUE(resource_provider_->InUseByConsumer(id2));
1350 1325
1351 // Release the resource in the parent. Set no resources as being in use. The 1326 // Release the resource in the parent. Set no resources as being in use. The
1352 // resources are exported so that can't be transferred back yet. 1327 // resources are exported so that can't be transferred back yet.
1353 ResourceProvider::ResourceIdArray no_resources; 1328 ResourceProvider::ResourceIdArray no_resources;
1354 resource_provider_->DeclareUsedResourcesFromChild(child_id, no_resources); 1329 resource_provider_->DeclareUsedResourcesFromChild(child_id, no_resources);
1355 1330
1356 EXPECT_EQ(0u, returned_to_child.size()); 1331 EXPECT_EQ(0u, returned_to_child.size());
1357 EXPECT_EQ(2u, resource_provider_->num_resources()); 1332 EXPECT_EQ(2u, resource_provider_->num_resources());
1358 1333
1359 // Return the resources from the grandparent to the parent. They should be 1334 // Return the resources from the grandparent to the parent. They should be
1360 // returned to the child then. 1335 // returned to the child then.
1361 EXPECT_EQ(2u, list.size()); 1336 EXPECT_EQ(2u, list.size());
1362 EXPECT_EQ(mapped_id1, list[0].id); 1337 EXPECT_EQ(mapped_id1, list[0].id);
1363 EXPECT_EQ(mapped_id2, list[1].id); 1338 EXPECT_EQ(mapped_id2, list[1].id);
1364 ReturnedResourceArray returned; 1339 ReturnedResourceArray returned;
1365 TransferableResource::ReturnResources(list, &returned); 1340 TransferableResource::ReturnResources(list, &returned);
1366 resource_provider_->ReceiveReturnsFromParent(returned); 1341 resource_provider_->ReceiveReturnsFromParent(returned);
1367 1342
1368 EXPECT_EQ(0u, resource_provider_->num_resources()); 1343 EXPECT_EQ(0u, resource_provider_->num_resources());
1369 ASSERT_EQ(2u, returned_to_child.size()); 1344 ASSERT_EQ(2u, returned_to_child.size());
1370 if (GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) { 1345 if (GetParam() == ResourceProvider::GLTexture) {
1371 EXPECT_NE(0u, returned_to_child[0].sync_point); 1346 EXPECT_NE(0u, returned_to_child[0].sync_point);
1372 EXPECT_NE(0u, returned_to_child[1].sync_point); 1347 EXPECT_NE(0u, returned_to_child[1].sync_point);
1373 } 1348 }
1374 EXPECT_FALSE(returned_to_child[0].lost); 1349 EXPECT_FALSE(returned_to_child[0].lost);
1375 EXPECT_FALSE(returned_to_child[1].lost); 1350 EXPECT_FALSE(returned_to_child[1].lost);
1376 } 1351 }
1377 } 1352 }
1378 1353
1379 TEST_P(ResourceProviderTest, DestroyChildWithExportedResources) { 1354 TEST_P(ResourceProviderTest, DestroyChildWithExportedResources) {
1380 gfx::Size size(1, 1); 1355 gfx::Size size(1, 1);
1381 ResourceFormat format = RGBA_8888; 1356 ResourceFormat format = RGBA_8888;
1382 size_t pixel_size = TextureSizeBytes(size, format); 1357 size_t pixel_size = TextureSizeBytes(size, format);
1383 ASSERT_EQ(4U, pixel_size); 1358 ASSERT_EQ(4U, pixel_size);
1384 1359
1385 ResourceProvider::ResourceId id1 = child_resource_provider_->CreateResource( 1360 ResourceProvider::ResourceId id1 = child_resource_provider_->CreateResource(
1386 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); 1361 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
1387 uint8_t data1[4] = {1, 2, 3, 4}; 1362 uint8_t data1[4] = {1, 2, 3, 4};
1388 child_resource_provider_->CopyToResource(id1, data1, size); 1363 gfx::Rect rect(size);
1364 child_resource_provider_->SetPixels(id1, data1, rect, rect, gfx::Vector2d());
1389 1365
1390 ResourceProvider::ResourceId id2 = child_resource_provider_->CreateResource( 1366 ResourceProvider::ResourceId id2 = child_resource_provider_->CreateResource(
1391 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); 1367 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
1392 uint8_t data2[4] = {5, 5, 5, 5}; 1368 uint8_t data2[4] = {5, 5, 5, 5};
1393 child_resource_provider_->CopyToResource(id2, data2, size); 1369 child_resource_provider_->SetPixels(id2, data2, rect, rect, gfx::Vector2d());
1394 1370
1395 ReturnedResourceArray returned_to_child; 1371 ReturnedResourceArray returned_to_child;
1396 int child_id = 1372 int child_id =
1397 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); 1373 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child));
1398 { 1374 {
1399 // Transfer some resources to the parent. 1375 // Transfer some resources to the parent.
1400 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 1376 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
1401 resource_ids_to_transfer.push_back(id1); 1377 resource_ids_to_transfer.push_back(id1);
1402 resource_ids_to_transfer.push_back(id2); 1378 resource_ids_to_transfer.push_back(id2);
1403 TransferableResourceArray list; 1379 TransferableResourceArray list;
1404 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, 1380 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer,
1405 &list); 1381 &list);
1406 ASSERT_EQ(2u, list.size()); 1382 ASSERT_EQ(2u, list.size());
1407 if (GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) { 1383 if (GetParam() == ResourceProvider::GLTexture) {
1408 EXPECT_NE(0u, list[0].mailbox_holder.sync_point); 1384 EXPECT_NE(0u, list[0].mailbox_holder.sync_point);
1409 EXPECT_NE(0u, list[1].mailbox_holder.sync_point); 1385 EXPECT_NE(0u, list[1].mailbox_holder.sync_point);
1410 } 1386 }
1411 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); 1387 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1));
1412 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2)); 1388 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2));
1413 resource_provider_->ReceiveFromChild(child_id, list); 1389 resource_provider_->ReceiveFromChild(child_id, list);
1414 resource_provider_->DeclareUsedResourcesFromChild(child_id, 1390 resource_provider_->DeclareUsedResourcesFromChild(child_id,
1415 resource_ids_to_transfer); 1391 resource_ids_to_transfer);
1416 } 1392 }
1417 1393
1418 EXPECT_EQ(2u, resource_provider_->num_resources()); 1394 EXPECT_EQ(2u, resource_provider_->num_resources());
1419 ResourceProvider::ResourceIdMap resource_map = 1395 ResourceProvider::ResourceIdMap resource_map =
1420 resource_provider_->GetChildToParentMap(child_id); 1396 resource_provider_->GetChildToParentMap(child_id);
1421 ResourceProvider::ResourceId mapped_id1 = resource_map[id1]; 1397 ResourceProvider::ResourceId mapped_id1 = resource_map[id1];
1422 ResourceProvider::ResourceId mapped_id2 = resource_map[id2]; 1398 ResourceProvider::ResourceId mapped_id2 = resource_map[id2];
1423 EXPECT_NE(0u, mapped_id1); 1399 EXPECT_NE(0u, mapped_id1);
1424 EXPECT_NE(0u, mapped_id2); 1400 EXPECT_NE(0u, mapped_id2);
1425 EXPECT_FALSE(resource_provider_->InUseByConsumer(id1)); 1401 EXPECT_FALSE(resource_provider_->InUseByConsumer(id1));
1426 EXPECT_FALSE(resource_provider_->InUseByConsumer(id2)); 1402 EXPECT_FALSE(resource_provider_->InUseByConsumer(id2));
1427 1403
1428 { 1404 {
1429 // The parent transfers the resources to the grandparent. 1405 // The parent transfers the resources to the grandparent.
1430 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 1406 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
1431 resource_ids_to_transfer.push_back(mapped_id1); 1407 resource_ids_to_transfer.push_back(mapped_id1);
1432 resource_ids_to_transfer.push_back(mapped_id2); 1408 resource_ids_to_transfer.push_back(mapped_id2);
1433 TransferableResourceArray list; 1409 TransferableResourceArray list;
1434 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list); 1410 resource_provider_->PrepareSendToParent(resource_ids_to_transfer, &list);
1435 1411
1436 ASSERT_EQ(2u, list.size()); 1412 ASSERT_EQ(2u, list.size());
1437 if (GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) { 1413 if (GetParam() == ResourceProvider::GLTexture) {
1438 EXPECT_NE(0u, list[0].mailbox_holder.sync_point); 1414 EXPECT_NE(0u, list[0].mailbox_holder.sync_point);
1439 EXPECT_NE(0u, list[1].mailbox_holder.sync_point); 1415 EXPECT_NE(0u, list[1].mailbox_holder.sync_point);
1440 } 1416 }
1441 EXPECT_TRUE(resource_provider_->InUseByConsumer(id1)); 1417 EXPECT_TRUE(resource_provider_->InUseByConsumer(id1));
1442 EXPECT_TRUE(resource_provider_->InUseByConsumer(id2)); 1418 EXPECT_TRUE(resource_provider_->InUseByConsumer(id2));
1443 1419
1444 // Release the resource in the parent. Set no resources as being in use. The 1420 // Release the resource in the parent. Set no resources as being in use. The
1445 // resources are exported so that can't be transferred back yet. 1421 // resources are exported so that can't be transferred back yet.
1446 ResourceProvider::ResourceIdArray no_resources; 1422 ResourceProvider::ResourceIdArray no_resources;
1447 resource_provider_->DeclareUsedResourcesFromChild(child_id, no_resources); 1423 resource_provider_->DeclareUsedResourcesFromChild(child_id, no_resources);
(...skipping 14 matching lines...) Expand all
1462 EXPECT_EQ(mapped_id2, list[1].id); 1438 EXPECT_EQ(mapped_id2, list[1].id);
1463 TransferableResourceArray return_list; 1439 TransferableResourceArray return_list;
1464 return_list.push_back(list[1]); 1440 return_list.push_back(list[1]);
1465 list.pop_back(); 1441 list.pop_back();
1466 ReturnedResourceArray returned; 1442 ReturnedResourceArray returned;
1467 TransferableResource::ReturnResources(return_list, &returned); 1443 TransferableResource::ReturnResources(return_list, &returned);
1468 resource_provider_->ReceiveReturnsFromParent(returned); 1444 resource_provider_->ReceiveReturnsFromParent(returned);
1469 1445
1470 EXPECT_EQ(1u, resource_provider_->num_resources()); 1446 EXPECT_EQ(1u, resource_provider_->num_resources());
1471 ASSERT_EQ(1u, returned_to_child.size()); 1447 ASSERT_EQ(1u, returned_to_child.size());
1472 if (GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) { 1448 if (GetParam() == ResourceProvider::GLTexture) {
1473 EXPECT_NE(0u, returned_to_child[0].sync_point); 1449 EXPECT_NE(0u, returned_to_child[0].sync_point);
1474 } 1450 }
1475 EXPECT_FALSE(returned_to_child[0].lost); 1451 EXPECT_FALSE(returned_to_child[0].lost);
1476 returned_to_child.clear(); 1452 returned_to_child.clear();
1477 1453
1478 // Destroy the parent resource provider. The resource that's left should be 1454 // Destroy the parent resource provider. The resource that's left should be
1479 // lost at this point, and returned. 1455 // lost at this point, and returned.
1480 resource_provider_ = nullptr; 1456 resource_provider_ = nullptr;
1481 ASSERT_EQ(1u, returned_to_child.size()); 1457 ASSERT_EQ(1u, returned_to_child.size());
1482 if (GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) { 1458 if (GetParam() == ResourceProvider::GLTexture) {
1483 EXPECT_NE(0u, returned_to_child[0].sync_point); 1459 EXPECT_NE(0u, returned_to_child[0].sync_point);
1484 } 1460 }
1485 EXPECT_TRUE(returned_to_child[0].lost); 1461 EXPECT_TRUE(returned_to_child[0].lost);
1486 } 1462 }
1487 } 1463 }
1488 1464
1489 TEST_P(ResourceProviderTest, DeleteTransferredResources) { 1465 TEST_P(ResourceProviderTest, DeleteTransferredResources) {
1490 gfx::Size size(1, 1); 1466 gfx::Size size(1, 1);
1491 ResourceFormat format = RGBA_8888; 1467 ResourceFormat format = RGBA_8888;
1492 size_t pixel_size = TextureSizeBytes(size, format); 1468 size_t pixel_size = TextureSizeBytes(size, format);
1493 ASSERT_EQ(4U, pixel_size); 1469 ASSERT_EQ(4U, pixel_size);
1494 1470
1495 ResourceProvider::ResourceId id = child_resource_provider_->CreateResource( 1471 ResourceProvider::ResourceId id = child_resource_provider_->CreateResource(
1496 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); 1472 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
1497 uint8_t data[4] = { 1, 2, 3, 4 }; 1473 uint8_t data[4] = { 1, 2, 3, 4 };
1498 child_resource_provider_->CopyToResource(id, data, size); 1474 gfx::Rect rect(size);
1475 child_resource_provider_->SetPixels(id, data, rect, rect, gfx::Vector2d());
1499 1476
1500 ReturnedResourceArray returned_to_child; 1477 ReturnedResourceArray returned_to_child;
1501 int child_id = 1478 int child_id =
1502 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); 1479 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child));
1503 { 1480 {
1504 // Transfer some resource to the parent. 1481 // Transfer some resource to the parent.
1505 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 1482 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
1506 resource_ids_to_transfer.push_back(id); 1483 resource_ids_to_transfer.push_back(id);
1507 TransferableResourceArray list; 1484 TransferableResourceArray list;
1508 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, 1485 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer,
1509 &list); 1486 &list);
1510 ASSERT_EQ(1u, list.size()); 1487 ASSERT_EQ(1u, list.size());
1511 if (GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 1488 if (GetParam() == ResourceProvider::GLTexture)
1512 EXPECT_NE(0u, list[0].mailbox_holder.sync_point); 1489 EXPECT_NE(0u, list[0].mailbox_holder.sync_point);
1513 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id)); 1490 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id));
1514 resource_provider_->ReceiveFromChild(child_id, list); 1491 resource_provider_->ReceiveFromChild(child_id, list);
1515 resource_provider_->DeclareUsedResourcesFromChild(child_id, 1492 resource_provider_->DeclareUsedResourcesFromChild(child_id,
1516 resource_ids_to_transfer); 1493 resource_ids_to_transfer);
1517 } 1494 }
1518 1495
1519 // Delete textures in the child, while they are transfered. 1496 // Delete textures in the child, while they are transfered.
1520 child_resource_provider_->DeleteResource(id); 1497 child_resource_provider_->DeleteResource(id);
1521 EXPECT_EQ(1u, child_resource_provider_->num_resources()); 1498 EXPECT_EQ(1u, child_resource_provider_->num_resources());
1522 { 1499 {
1523 EXPECT_EQ(0u, returned_to_child.size()); 1500 EXPECT_EQ(0u, returned_to_child.size());
1524 1501
1525 // Transfer resources back from the parent to the child. Set no resources as 1502 // Transfer resources back from the parent to the child. Set no resources as
1526 // being in use. 1503 // being in use.
1527 ResourceProvider::ResourceIdArray no_resources; 1504 ResourceProvider::ResourceIdArray no_resources;
1528 resource_provider_->DeclareUsedResourcesFromChild(child_id, no_resources); 1505 resource_provider_->DeclareUsedResourcesFromChild(child_id, no_resources);
1529 1506
1530 ASSERT_EQ(1u, returned_to_child.size()); 1507 ASSERT_EQ(1u, returned_to_child.size());
1531 if (GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 1508 if (GetParam() == ResourceProvider::GLTexture)
1532 EXPECT_NE(0u, returned_to_child[0].sync_point); 1509 EXPECT_NE(0u, returned_to_child[0].sync_point);
1533 child_resource_provider_->ReceiveReturnsFromParent(returned_to_child); 1510 child_resource_provider_->ReceiveReturnsFromParent(returned_to_child);
1534 } 1511 }
1535 EXPECT_EQ(0u, child_resource_provider_->num_resources()); 1512 EXPECT_EQ(0u, child_resource_provider_->num_resources());
1536 } 1513 }
1537 1514
1538 TEST_P(ResourceProviderTest, UnuseTransferredResources) { 1515 TEST_P(ResourceProviderTest, UnuseTransferredResources) {
1539 gfx::Size size(1, 1); 1516 gfx::Size size(1, 1);
1540 ResourceFormat format = RGBA_8888; 1517 ResourceFormat format = RGBA_8888;
1541 size_t pixel_size = TextureSizeBytes(size, format); 1518 size_t pixel_size = TextureSizeBytes(size, format);
1542 ASSERT_EQ(4U, pixel_size); 1519 ASSERT_EQ(4U, pixel_size);
1543 1520
1544 ResourceProvider::ResourceId id = child_resource_provider_->CreateResource( 1521 ResourceProvider::ResourceId id = child_resource_provider_->CreateResource(
1545 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); 1522 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
1546 uint8_t data[4] = {1, 2, 3, 4}; 1523 uint8_t data[4] = {1, 2, 3, 4};
1547 child_resource_provider_->CopyToResource(id, data, size); 1524 gfx::Rect rect(size);
1525 child_resource_provider_->SetPixels(id, data, rect, rect, gfx::Vector2d());
1548 1526
1549 ReturnedResourceArray returned_to_child; 1527 ReturnedResourceArray returned_to_child;
1550 int child_id = 1528 int child_id =
1551 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); 1529 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child));
1552 const ResourceProvider::ResourceIdMap& map = 1530 const ResourceProvider::ResourceIdMap& map =
1553 resource_provider_->GetChildToParentMap(child_id); 1531 resource_provider_->GetChildToParentMap(child_id);
1554 { 1532 {
1555 // Transfer some resource to the parent. 1533 // Transfer some resource to the parent.
1556 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 1534 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
1557 resource_ids_to_transfer.push_back(id); 1535 resource_ids_to_transfer.push_back(id);
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1687 1665
1688 gfx::Size size(1, 1); 1666 gfx::Size size(1, 1);
1689 ResourceFormat format = RGBA_8888; 1667 ResourceFormat format = RGBA_8888;
1690 int child_texture_id = 1; 1668 int child_texture_id = 1;
1691 int parent_texture_id = 2; 1669 int parent_texture_id = 2;
1692 1670
1693 size_t pixel_size = TextureSizeBytes(size, format); 1671 size_t pixel_size = TextureSizeBytes(size, format);
1694 ASSERT_EQ(4U, pixel_size); 1672 ASSERT_EQ(4U, pixel_size);
1695 1673
1696 ResourceProvider::ResourceId id = child_resource_provider->CreateResource( 1674 ResourceProvider::ResourceId id = child_resource_provider->CreateResource(
1697 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, 1675 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
1698 format);
1699 1676
1700 // The new texture is created with GL_LINEAR. 1677 // The new texture is created with GL_LINEAR.
1701 EXPECT_CALL(*child_context, bindTexture(GL_TEXTURE_2D, child_texture_id)) 1678 EXPECT_CALL(*child_context, bindTexture(GL_TEXTURE_2D, child_texture_id))
1702 .Times(2); // Once to create and once to allocate. 1679 .Times(2); // Once to create and once to allocate.
1703 EXPECT_CALL(*child_context, 1680 EXPECT_CALL(*child_context,
1704 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); 1681 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
1705 EXPECT_CALL(*child_context, 1682 EXPECT_CALL(*child_context,
1706 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); 1683 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
1707 EXPECT_CALL( 1684 EXPECT_CALL(
1708 *child_context, 1685 *child_context,
1709 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); 1686 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
1710 EXPECT_CALL( 1687 EXPECT_CALL(
1711 *child_context, 1688 *child_context,
1712 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); 1689 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
1713 EXPECT_CALL(*child_context, 1690 EXPECT_CALL(*child_context,
1714 texParameteri(GL_TEXTURE_2D, 1691 texParameteri(GL_TEXTURE_2D,
1715 GL_TEXTURE_POOL_CHROMIUM, 1692 GL_TEXTURE_POOL_CHROMIUM,
1716 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM)); 1693 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM));
1717 child_resource_provider->AllocateForTesting(id); 1694 child_resource_provider->AllocateForTesting(id);
1718 Mock::VerifyAndClearExpectations(child_context); 1695 Mock::VerifyAndClearExpectations(child_context);
1719 1696
1720 uint8_t data[4] = { 1, 2, 3, 4 }; 1697 uint8_t data[4] = { 1, 2, 3, 4 };
1698 gfx::Rect rect(size);
1721 1699
1722 EXPECT_CALL(*child_context, bindTexture(GL_TEXTURE_2D, child_texture_id)); 1700 EXPECT_CALL(*child_context, bindTexture(GL_TEXTURE_2D, child_texture_id));
1723 child_resource_provider->CopyToResource(id, data, size); 1701 child_resource_provider->SetPixels(id, data, rect, rect, gfx::Vector2d());
1724 Mock::VerifyAndClearExpectations(child_context); 1702 Mock::VerifyAndClearExpectations(child_context);
1725 1703
1726 // The texture is set to |child_filter| in the child. 1704 // The texture is set to |child_filter| in the child.
1727 EXPECT_CALL(*child_context, bindTexture(GL_TEXTURE_2D, child_texture_id)); 1705 EXPECT_CALL(*child_context, bindTexture(GL_TEXTURE_2D, child_texture_id));
1728 if (child_filter != GL_LINEAR) { 1706 if (child_filter != GL_LINEAR) {
1729 EXPECT_CALL( 1707 EXPECT_CALL(
1730 *child_context, 1708 *child_context,
1731 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, child_filter)); 1709 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, child_filter));
1732 EXPECT_CALL( 1710 EXPECT_CALL(
1733 *child_context, 1711 *child_context,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1813 } 1791 }
1814 1792
1815 // The child remembers the texture filter is set to |child_filter|. 1793 // The child remembers the texture filter is set to |child_filter|.
1816 EXPECT_CALL(*child_context, bindTexture(GL_TEXTURE_2D, child_texture_id)); 1794 EXPECT_CALL(*child_context, bindTexture(GL_TEXTURE_2D, child_texture_id));
1817 SetResourceFilter(child_resource_provider.get(), id, child_filter); 1795 SetResourceFilter(child_resource_provider.get(), id, child_filter);
1818 Mock::VerifyAndClearExpectations(child_context); 1796 Mock::VerifyAndClearExpectations(child_context);
1819 } 1797 }
1820 }; 1798 };
1821 1799
1822 TEST_P(ResourceProviderTest, TextureFilters_ChildNearestParentLinear) { 1800 TEST_P(ResourceProviderTest, TextureFilters_ChildNearestParentLinear) {
1823 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 1801 if (GetParam() != ResourceProvider::GLTexture)
1824 return; 1802 return;
1825 ResourceProviderTestTextureFilters::RunTest(GL_NEAREST, GL_LINEAR); 1803 ResourceProviderTestTextureFilters::RunTest(GL_NEAREST, GL_LINEAR);
1826 } 1804 }
1827 1805
1828 TEST_P(ResourceProviderTest, TextureFilters_ChildLinearParentNearest) { 1806 TEST_P(ResourceProviderTest, TextureFilters_ChildLinearParentNearest) {
1829 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 1807 if (GetParam() != ResourceProvider::GLTexture)
1830 return; 1808 return;
1831 ResourceProviderTestTextureFilters::RunTest(GL_LINEAR, GL_NEAREST); 1809 ResourceProviderTestTextureFilters::RunTest(GL_LINEAR, GL_NEAREST);
1832 } 1810 }
1833 1811
1834 TEST_P(ResourceProviderTest, TransferMailboxResources) { 1812 TEST_P(ResourceProviderTest, TransferMailboxResources) {
1835 // Other mailbox transfers tested elsewhere. 1813 // Other mailbox transfers tested elsewhere.
1836 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 1814 if (GetParam() != ResourceProvider::GLTexture)
1837 return; 1815 return;
1838 unsigned texture = context()->createTexture(); 1816 unsigned texture = context()->createTexture();
1839 context()->bindTexture(GL_TEXTURE_2D, texture); 1817 context()->bindTexture(GL_TEXTURE_2D, texture);
1840 uint8_t data[4] = { 1, 2, 3, 4 }; 1818 uint8_t data[4] = { 1, 2, 3, 4 };
1841 context()->texImage2D( 1819 context()->texImage2D(
1842 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &data); 1820 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &data);
1843 gpu::Mailbox mailbox; 1821 gpu::Mailbox mailbox;
1844 context()->genMailboxCHROMIUM(mailbox.name); 1822 context()->genMailboxCHROMIUM(mailbox.name);
1845 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); 1823 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
1846 uint32 sync_point = context()->insertSyncPoint(); 1824 uint32 sync_point = context()->insertSyncPoint();
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1958 context()->bindTexture(GL_TEXTURE_2D, texture); 1936 context()->bindTexture(GL_TEXTURE_2D, texture);
1959 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); 1937 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
1960 context()->deleteTexture(texture); 1938 context()->deleteTexture(texture);
1961 } 1939 }
1962 1940
1963 TEST_P(ResourceProviderTest, LostResourceInParent) { 1941 TEST_P(ResourceProviderTest, LostResourceInParent) {
1964 gfx::Size size(1, 1); 1942 gfx::Size size(1, 1);
1965 ResourceFormat format = RGBA_8888; 1943 ResourceFormat format = RGBA_8888;
1966 ResourceProvider::ResourceId resource = 1944 ResourceProvider::ResourceId resource =
1967 child_resource_provider_->CreateResource( 1945 child_resource_provider_->CreateResource(
1968 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, 1946 size,
1947 GL_CLAMP_TO_EDGE,
1948 ResourceProvider::TextureHintImmutable,
1969 format); 1949 format);
1970 child_resource_provider_->AllocateForTesting(resource); 1950 child_resource_provider_->AllocateForTesting(resource);
1971 // Expect a GL resource to be lost. 1951 // Expect a GL resource to be lost.
1972 bool should_lose_resource = 1952 bool should_lose_resource = GetParam() == ResourceProvider::GLTexture;
1973 GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE;
1974 1953
1975 ReturnedResourceArray returned_to_child; 1954 ReturnedResourceArray returned_to_child;
1976 int child_id = 1955 int child_id =
1977 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); 1956 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child));
1978 { 1957 {
1979 // Transfer the resource to the parent. 1958 // Transfer the resource to the parent.
1980 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 1959 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
1981 resource_ids_to_transfer.push_back(resource); 1960 resource_ids_to_transfer.push_back(resource);
1982 TransferableResourceArray list; 1961 TransferableResourceArray list;
1983 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, 1962 child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer,
(...skipping 29 matching lines...) Expand all
2013 // Lost resources stay in use in the parent forever. 1992 // Lost resources stay in use in the parent forever.
2014 EXPECT_EQ(should_lose_resource, 1993 EXPECT_EQ(should_lose_resource,
2015 child_resource_provider_->InUseByConsumer(resource)); 1994 child_resource_provider_->InUseByConsumer(resource));
2016 } 1995 }
2017 1996
2018 TEST_P(ResourceProviderTest, LostResourceInGrandParent) { 1997 TEST_P(ResourceProviderTest, LostResourceInGrandParent) {
2019 gfx::Size size(1, 1); 1998 gfx::Size size(1, 1);
2020 ResourceFormat format = RGBA_8888; 1999 ResourceFormat format = RGBA_8888;
2021 ResourceProvider::ResourceId resource = 2000 ResourceProvider::ResourceId resource =
2022 child_resource_provider_->CreateResource( 2001 child_resource_provider_->CreateResource(
2023 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, 2002 size,
2003 GL_CLAMP_TO_EDGE,
2004 ResourceProvider::TextureHintImmutable,
2024 format); 2005 format);
2025 child_resource_provider_->AllocateForTesting(resource); 2006 child_resource_provider_->AllocateForTesting(resource);
2026 2007
2027 ReturnedResourceArray returned_to_child; 2008 ReturnedResourceArray returned_to_child;
2028 int child_id = 2009 int child_id =
2029 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); 2010 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child));
2030 { 2011 {
2031 // Transfer the resource to the parent. 2012 // Transfer the resource to the parent.
2032 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 2013 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
2033 resource_ids_to_transfer.push_back(resource); 2014 resource_ids_to_transfer.push_back(resource);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
2124 EXPECT_EQ(0u, returned_to_child.size()); 2105 EXPECT_EQ(0u, returned_to_child.size());
2125 2106
2126 // Transfer resources back from the parent to the child. Set no resources as 2107 // Transfer resources back from the parent to the child. Set no resources as
2127 // being in use. 2108 // being in use.
2128 ResourceProvider::ResourceIdArray no_resources; 2109 ResourceProvider::ResourceIdArray no_resources;
2129 resource_provider_->DeclareUsedResourcesFromChild(child_id, no_resources); 2110 resource_provider_->DeclareUsedResourcesFromChild(child_id, no_resources);
2130 2111
2131 ASSERT_EQ(1u, returned_to_child.size()); 2112 ASSERT_EQ(1u, returned_to_child.size());
2132 // Losing an output surface only loses hardware resources. 2113 // Losing an output surface only loses hardware resources.
2133 EXPECT_EQ(returned_to_child[0].lost, 2114 EXPECT_EQ(returned_to_child[0].lost,
2134 GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE); 2115 GetParam() == ResourceProvider::GLTexture);
2135 child_resource_provider_->ReceiveReturnsFromParent(returned_to_child); 2116 child_resource_provider_->ReceiveReturnsFromParent(returned_to_child);
2136 returned_to_child.clear(); 2117 returned_to_child.clear();
2137 } 2118 }
2138 2119
2139 // Delete the resource in the child. Expect the resource to be lost if it's 2120 // Delete the resource in the child. Expect the resource to be lost if it's
2140 // a GL texture. 2121 // a GL texture.
2141 child_resource_provider_->DeleteResource(resource); 2122 child_resource_provider_->DeleteResource(resource);
2142 EXPECT_EQ(lost_resource, 2123 EXPECT_EQ(lost_resource, GetParam() == ResourceProvider::GLTexture);
2143 GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE);
2144 } 2124 }
2145 2125
2146 TEST_P(ResourceProviderTest, LostMailboxInGrandParent) { 2126 TEST_P(ResourceProviderTest, LostMailboxInGrandParent) {
2147 uint32 release_sync_point = 0; 2127 uint32 release_sync_point = 0;
2148 bool lost_resource = false; 2128 bool lost_resource = false;
2149 bool release_called = false; 2129 bool release_called = false;
2150 uint32 sync_point = 0; 2130 uint32 sync_point = 0;
2151 ResourceProvider::ResourceId resource = CreateChildMailbox( 2131 ResourceProvider::ResourceId resource = CreateChildMailbox(
2152 &release_sync_point, &lost_resource, &release_called, &sync_point); 2132 &release_sync_point, &lost_resource, &release_called, &sync_point);
2153 2133
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
2217 bool release_called = false; 2197 bool release_called = false;
2218 uint32 sync_point = 0; 2198 uint32 sync_point = 0;
2219 CreateChildMailbox( 2199 CreateChildMailbox(
2220 &release_sync_point, &lost_resource, &release_called, &sync_point); 2200 &release_sync_point, &lost_resource, &release_called, &sync_point);
2221 2201
2222 EXPECT_EQ(0u, release_sync_point); 2202 EXPECT_EQ(0u, release_sync_point);
2223 EXPECT_FALSE(lost_resource); 2203 EXPECT_FALSE(lost_resource);
2224 2204
2225 child_resource_provider_ = nullptr; 2205 child_resource_provider_ = nullptr;
2226 2206
2227 if (GetParam() == ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) { 2207 if (GetParam() == ResourceProvider::GLTexture) {
2228 EXPECT_LE(sync_point, release_sync_point); 2208 EXPECT_LE(sync_point, release_sync_point);
2229 } 2209 }
2230 EXPECT_TRUE(release_called); 2210 EXPECT_TRUE(release_called);
2231 EXPECT_FALSE(lost_resource); 2211 EXPECT_FALSE(lost_resource);
2232 } 2212 }
2233 2213
2234 TEST_P(ResourceProviderTest, ShutdownWithExportedResource) { 2214 TEST_P(ResourceProviderTest, ShutdownWithExportedResource) {
2235 uint32 release_sync_point = 0; 2215 uint32 release_sync_point = 0;
2236 bool lost_resource = false; 2216 bool lost_resource = false;
2237 bool release_called = false; 2217 bool release_called = false;
(...skipping 13 matching lines...) Expand all
2251 2231
2252 child_resource_provider_ = nullptr; 2232 child_resource_provider_ = nullptr;
2253 2233
2254 // Since the resource is in the parent, the child considers it lost. 2234 // Since the resource is in the parent, the child considers it lost.
2255 EXPECT_EQ(0u, release_sync_point); 2235 EXPECT_EQ(0u, release_sync_point);
2256 EXPECT_TRUE(lost_resource); 2236 EXPECT_TRUE(lost_resource);
2257 } 2237 }
2258 2238
2259 TEST_P(ResourceProviderTest, LostContext) { 2239 TEST_P(ResourceProviderTest, LostContext) {
2260 // TextureMailbox callbacks only exist for GL textures for now. 2240 // TextureMailbox callbacks only exist for GL textures for now.
2261 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 2241 if (GetParam() != ResourceProvider::GLTexture)
2262 return; 2242 return;
2263 unsigned texture = context()->createTexture(); 2243 unsigned texture = context()->createTexture();
2264 context()->bindTexture(GL_TEXTURE_2D, texture); 2244 context()->bindTexture(GL_TEXTURE_2D, texture);
2265 gpu::Mailbox mailbox; 2245 gpu::Mailbox mailbox;
2266 context()->genMailboxCHROMIUM(mailbox.name); 2246 context()->genMailboxCHROMIUM(mailbox.name);
2267 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); 2247 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
2268 uint32 sync_point = context()->insertSyncPoint(); 2248 uint32 sync_point = context()->insertSyncPoint();
2269 2249
2270 EXPECT_LT(0u, sync_point); 2250 EXPECT_LT(0u, sync_point);
2271 2251
(...skipping 15 matching lines...) Expand all
2287 resource_provider_->DidLoseOutputSurface(); 2267 resource_provider_->DidLoseOutputSurface();
2288 resource_provider_ = nullptr; 2268 resource_provider_ = nullptr;
2289 2269
2290 EXPECT_LE(sync_point, release_sync_point); 2270 EXPECT_LE(sync_point, release_sync_point);
2291 EXPECT_TRUE(lost_resource); 2271 EXPECT_TRUE(lost_resource);
2292 EXPECT_EQ(main_thread_task_runner_.get(), main_thread_task_runner); 2272 EXPECT_EQ(main_thread_task_runner_.get(), main_thread_task_runner);
2293 } 2273 }
2294 2274
2295 TEST_P(ResourceProviderTest, ScopedSampler) { 2275 TEST_P(ResourceProviderTest, ScopedSampler) {
2296 // Sampling is only supported for GL textures. 2276 // Sampling is only supported for GL textures.
2297 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 2277 if (GetParam() != ResourceProvider::GLTexture)
2298 return; 2278 return;
2299 2279
2300 scoped_ptr<TextureStateTrackingContext> context_owned( 2280 scoped_ptr<TextureStateTrackingContext> context_owned(
2301 new TextureStateTrackingContext); 2281 new TextureStateTrackingContext);
2302 TextureStateTrackingContext* context = context_owned.get(); 2282 TextureStateTrackingContext* context = context_owned.get();
2303 2283
2304 FakeOutputSurfaceClient output_surface_client; 2284 FakeOutputSurfaceClient output_surface_client;
2305 scoped_ptr<OutputSurface> output_surface( 2285 scoped_ptr<OutputSurface> output_surface(
2306 FakeOutputSurface::Create3d(context_owned.Pass())); 2286 FakeOutputSurface::Create3d(context_owned.Pass()));
2307 CHECK(output_surface->BindToClient(&output_surface_client)); 2287 CHECK(output_surface->BindToClient(&output_surface_client));
2308 2288
2309 scoped_ptr<ResourceProvider> resource_provider( 2289 scoped_ptr<ResourceProvider> resource_provider(
2310 ResourceProvider::Create(output_surface.get(), 2290 ResourceProvider::Create(output_surface.get(),
2311 shared_bitmap_manager_.get(), 2291 shared_bitmap_manager_.get(),
2312 gpu_memory_buffer_manager_.get(), 2292 gpu_memory_buffer_manager_.get(),
2313 NULL, 2293 NULL,
2314 0, 2294 0,
2315 false, 2295 false,
2316 1)); 2296 1));
2317 2297
2318 gfx::Size size(1, 1); 2298 gfx::Size size(1, 1);
2319 ResourceFormat format = RGBA_8888; 2299 ResourceFormat format = RGBA_8888;
2320 int texture_id = 1; 2300 int texture_id = 1;
2321 2301
2322 ResourceProvider::ResourceId id = resource_provider->CreateResource( 2302 ResourceProvider::ResourceId id = resource_provider->CreateResource(
2323 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); 2303 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
2324 2304
2325 // Check that the texture gets created with the right sampler settings. 2305 // Check that the texture gets created with the right sampler settings.
2326 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)) 2306 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id))
2327 .Times(2); // Once to create and once to allocate. 2307 .Times(2); // Once to create and once to allocate.
2328 EXPECT_CALL(*context, 2308 EXPECT_CALL(*context,
2329 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); 2309 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
2330 EXPECT_CALL(*context, 2310 EXPECT_CALL(*context,
2331 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); 2311 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
2332 EXPECT_CALL( 2312 EXPECT_CALL(
2333 *context, 2313 *context,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2374 EXPECT_CALL(*context, 2354 EXPECT_CALL(*context,
2375 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); 2355 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
2376 ResourceProvider::ScopedSamplerGL sampler( 2356 ResourceProvider::ScopedSamplerGL sampler(
2377 resource_provider.get(), id, GL_TEXTURE_2D, GL_LINEAR); 2357 resource_provider.get(), id, GL_TEXTURE_2D, GL_LINEAR);
2378 Mock::VerifyAndClearExpectations(context); 2358 Mock::VerifyAndClearExpectations(context);
2379 } 2359 }
2380 } 2360 }
2381 2361
2382 TEST_P(ResourceProviderTest, ManagedResource) { 2362 TEST_P(ResourceProviderTest, ManagedResource) {
2383 // Sampling is only supported for GL textures. 2363 // Sampling is only supported for GL textures.
2384 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 2364 if (GetParam() != ResourceProvider::GLTexture)
2385 return; 2365 return;
2386 2366
2387 scoped_ptr<TextureStateTrackingContext> context_owned( 2367 scoped_ptr<TextureStateTrackingContext> context_owned(
2388 new TextureStateTrackingContext); 2368 new TextureStateTrackingContext);
2389 TextureStateTrackingContext* context = context_owned.get(); 2369 TextureStateTrackingContext* context = context_owned.get();
2390 2370
2391 FakeOutputSurfaceClient output_surface_client; 2371 FakeOutputSurfaceClient output_surface_client;
2392 scoped_ptr<OutputSurface> output_surface( 2372 scoped_ptr<OutputSurface> output_surface(
2393 FakeOutputSurface::Create3d(context_owned.Pass())); 2373 FakeOutputSurface::Create3d(context_owned.Pass()));
2394 CHECK(output_surface->BindToClient(&output_surface_client)); 2374 CHECK(output_surface->BindToClient(&output_surface_client));
2395 2375
2396 scoped_ptr<ResourceProvider> resource_provider( 2376 scoped_ptr<ResourceProvider> resource_provider(
2397 ResourceProvider::Create(output_surface.get(), 2377 ResourceProvider::Create(output_surface.get(),
2398 shared_bitmap_manager_.get(), 2378 shared_bitmap_manager_.get(),
2399 gpu_memory_buffer_manager_.get(), 2379 gpu_memory_buffer_manager_.get(),
2400 NULL, 2380 NULL,
2401 0, 2381 0,
2402 false, 2382 false,
2403 1)); 2383 1));
2404 2384
2405 gfx::Size size(1, 1); 2385 gfx::Size size(1, 1);
2406 ResourceFormat format = RGBA_8888; 2386 ResourceFormat format = RGBA_8888;
2407 int texture_id = 1; 2387 int texture_id = 1;
2408 2388
2409 // Check that the texture gets created with the right sampler settings. 2389 // Check that the texture gets created with the right sampler settings.
2410 ResourceProvider::ResourceId id = resource_provider->CreateManagedResource( 2390 ResourceProvider::ResourceId id = resource_provider->CreateManagedResource(
2411 size, GL_TEXTURE_2D, GL_CLAMP_TO_EDGE, 2391 size,
2412 ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); 2392 GL_TEXTURE_2D,
2393 GL_CLAMP_TO_EDGE,
2394 ResourceProvider::TextureHintImmutable,
2395 format);
2413 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)); 2396 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id));
2414 EXPECT_CALL(*context, 2397 EXPECT_CALL(*context,
2415 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); 2398 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
2416 EXPECT_CALL(*context, 2399 EXPECT_CALL(*context,
2417 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); 2400 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
2418 EXPECT_CALL( 2401 EXPECT_CALL(
2419 *context, 2402 *context,
2420 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); 2403 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
2421 EXPECT_CALL( 2404 EXPECT_CALL(
2422 *context, 2405 *context,
2423 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); 2406 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
2424 EXPECT_CALL(*context, 2407 EXPECT_CALL(*context,
2425 texParameteri(GL_TEXTURE_2D, 2408 texParameteri(GL_TEXTURE_2D,
2426 GL_TEXTURE_POOL_CHROMIUM, 2409 GL_TEXTURE_POOL_CHROMIUM,
2427 GL_TEXTURE_POOL_MANAGED_CHROMIUM)); 2410 GL_TEXTURE_POOL_MANAGED_CHROMIUM));
2428 resource_provider->CreateForTesting(id); 2411 resource_provider->CreateForTesting(id);
2429 EXPECT_NE(0u, id); 2412 EXPECT_NE(0u, id);
2430 2413
2431 Mock::VerifyAndClearExpectations(context); 2414 Mock::VerifyAndClearExpectations(context);
2432 } 2415 }
2433 2416
2434 TEST_P(ResourceProviderTest, TextureWrapMode) { 2417 TEST_P(ResourceProviderTest, TextureWrapMode) {
2435 // Sampling is only supported for GL textures. 2418 // Sampling is only supported for GL textures.
2436 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 2419 if (GetParam() != ResourceProvider::GLTexture)
2437 return; 2420 return;
2438 2421
2439 scoped_ptr<TextureStateTrackingContext> context_owned( 2422 scoped_ptr<TextureStateTrackingContext> context_owned(
2440 new TextureStateTrackingContext); 2423 new TextureStateTrackingContext);
2441 TextureStateTrackingContext* context = context_owned.get(); 2424 TextureStateTrackingContext* context = context_owned.get();
2442 2425
2443 FakeOutputSurfaceClient output_surface_client; 2426 FakeOutputSurfaceClient output_surface_client;
2444 scoped_ptr<OutputSurface> output_surface( 2427 scoped_ptr<OutputSurface> output_surface(
2445 FakeOutputSurface::Create3d(context_owned.Pass())); 2428 FakeOutputSurface::Create3d(context_owned.Pass()));
2446 CHECK(output_surface->BindToClient(&output_surface_client)); 2429 CHECK(output_surface->BindToClient(&output_surface_client));
2447 2430
2448 scoped_ptr<ResourceProvider> resource_provider( 2431 scoped_ptr<ResourceProvider> resource_provider(
2449 ResourceProvider::Create(output_surface.get(), 2432 ResourceProvider::Create(output_surface.get(),
2450 shared_bitmap_manager_.get(), 2433 shared_bitmap_manager_.get(),
2451 gpu_memory_buffer_manager_.get(), 2434 gpu_memory_buffer_manager_.get(),
2452 NULL, 2435 NULL,
2453 0, 2436 0,
2454 false, 2437 false,
2455 1)); 2438 1));
2456 2439
2457 gfx::Size size(1, 1); 2440 gfx::Size size(1, 1);
2458 ResourceFormat format = RGBA_8888; 2441 ResourceFormat format = RGBA_8888;
2459 GLenum texture_pool = GL_TEXTURE_POOL_UNMANAGED_CHROMIUM; 2442 GLenum texture_pool = GL_TEXTURE_POOL_UNMANAGED_CHROMIUM;
2460 2443
2461 for (int texture_id = 1; texture_id <= 2; ++texture_id) { 2444 for (int texture_id = 1; texture_id <= 2; ++texture_id) {
2462 GLint wrap_mode = texture_id == 1 ? GL_CLAMP_TO_EDGE : GL_REPEAT; 2445 GLint wrap_mode = texture_id == 1 ? GL_CLAMP_TO_EDGE : GL_REPEAT;
2463 // Check that the texture gets created with the right sampler settings. 2446 // Check that the texture gets created with the right sampler settings.
2464 ResourceProvider::ResourceId id = resource_provider->CreateGLTexture( 2447 ResourceProvider::ResourceId id = resource_provider->CreateGLTexture(
2465 size, GL_TEXTURE_2D, texture_pool, wrap_mode, 2448 size,
2466 ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); 2449 GL_TEXTURE_2D,
2450 texture_pool,
2451 wrap_mode,
2452 ResourceProvider::TextureHintImmutable,
2453 format);
2467 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)); 2454 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id));
2468 EXPECT_CALL(*context, 2455 EXPECT_CALL(*context,
2469 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); 2456 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
2470 EXPECT_CALL(*context, 2457 EXPECT_CALL(*context,
2471 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); 2458 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
2472 EXPECT_CALL(*context, 2459 EXPECT_CALL(*context,
2473 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_mode)); 2460 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_mode));
2474 EXPECT_CALL(*context, 2461 EXPECT_CALL(*context,
2475 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_mode)); 2462 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_mode));
2476 EXPECT_CALL(*context, 2463 EXPECT_CALL(*context,
2477 texParameteri(GL_TEXTURE_2D, 2464 texParameteri(GL_TEXTURE_2D,
2478 GL_TEXTURE_POOL_CHROMIUM, 2465 GL_TEXTURE_POOL_CHROMIUM,
2479 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM)); 2466 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM));
2480 resource_provider->CreateForTesting(id); 2467 resource_provider->CreateForTesting(id);
2481 EXPECT_NE(0u, id); 2468 EXPECT_NE(0u, id);
2482 2469
2483 Mock::VerifyAndClearExpectations(context); 2470 Mock::VerifyAndClearExpectations(context);
2484 } 2471 }
2485 } 2472 }
2486 2473
2487 TEST_P(ResourceProviderTest, TextureHint) { 2474 TEST_P(ResourceProviderTest, TextureHint) {
2488 // Sampling is only supported for GL textures. 2475 // Sampling is only supported for GL textures.
2489 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 2476 if (GetParam() != ResourceProvider::GLTexture)
2490 return; 2477 return;
2491 2478
2492 scoped_ptr<TextureStateTrackingContext> context_owned( 2479 scoped_ptr<TextureStateTrackingContext> context_owned(
2493 new TextureStateTrackingContext); 2480 new TextureStateTrackingContext);
2494 TextureStateTrackingContext* context = context_owned.get(); 2481 TextureStateTrackingContext* context = context_owned.get();
2495 context->set_support_texture_storage(true); 2482 context->set_support_texture_storage(true);
2496 context->set_support_texture_usage(true); 2483 context->set_support_texture_usage(true);
2497 2484
2498 FakeOutputSurfaceClient output_surface_client; 2485 FakeOutputSurfaceClient output_surface_client;
2499 scoped_ptr<OutputSurface> output_surface( 2486 scoped_ptr<OutputSurface> output_surface(
2500 FakeOutputSurface::Create3d(context_owned.Pass())); 2487 FakeOutputSurface::Create3d(context_owned.Pass()));
2501 CHECK(output_surface->BindToClient(&output_surface_client)); 2488 CHECK(output_surface->BindToClient(&output_surface_client));
2502 2489
2503 scoped_ptr<ResourceProvider> resource_provider( 2490 scoped_ptr<ResourceProvider> resource_provider(
2504 ResourceProvider::Create(output_surface.get(), 2491 ResourceProvider::Create(output_surface.get(),
2505 shared_bitmap_manager_.get(), 2492 shared_bitmap_manager_.get(),
2506 gpu_memory_buffer_manager_.get(), 2493 gpu_memory_buffer_manager_.get(),
2507 NULL, 2494 NULL,
2508 0, 2495 0,
2509 false, 2496 false,
2510 1)); 2497 1));
2511 2498
2512 gfx::Size size(1, 1); 2499 gfx::Size size(1, 1);
2513 ResourceFormat format = RGBA_8888; 2500 ResourceFormat format = RGBA_8888;
2514 GLenum texture_pool = GL_TEXTURE_POOL_UNMANAGED_CHROMIUM; 2501 GLenum texture_pool = GL_TEXTURE_POOL_UNMANAGED_CHROMIUM;
2515 2502
2516 const ResourceProvider::TextureHint hints[4] = { 2503 const ResourceProvider::TextureHint hints[4] = {
2517 ResourceProvider::TEXTURE_HINT_DEFAULT, 2504 ResourceProvider::TextureHintDefault,
2518 ResourceProvider::TEXTURE_HINT_IMMUTABLE, 2505 ResourceProvider::TextureHintImmutable,
2519 ResourceProvider::TEXTURE_HINT_FRAMEBUFFER, 2506 ResourceProvider::TextureHintFramebuffer,
2520 ResourceProvider::TEXTURE_HINT_IMMUTABLE_FRAMEBUFFER, 2507 ResourceProvider::TextureHintImmutableFramebuffer,
2521 }; 2508 };
2522 for (GLuint texture_id = 1; texture_id <= arraysize(hints); ++texture_id) { 2509 for (GLuint texture_id = 1; texture_id <= arraysize(hints); ++texture_id) {
2523 // Check that the texture gets created with the right sampler settings. 2510 // Check that the texture gets created with the right sampler settings.
2524 ResourceProvider::ResourceId id = 2511 ResourceProvider::ResourceId id =
2525 resource_provider->CreateGLTexture(size, 2512 resource_provider->CreateGLTexture(size,
2526 GL_TEXTURE_2D, 2513 GL_TEXTURE_2D,
2527 texture_pool, 2514 texture_pool,
2528 GL_CLAMP_TO_EDGE, 2515 GL_CLAMP_TO_EDGE,
2529 hints[texture_id - 1], 2516 hints[texture_id - 1],
2530 format); 2517 format);
2531 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)); 2518 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id));
2532 EXPECT_CALL(*context, 2519 EXPECT_CALL(*context,
2533 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); 2520 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
2534 EXPECT_CALL(*context, 2521 EXPECT_CALL(*context,
2535 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); 2522 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
2536 EXPECT_CALL( 2523 EXPECT_CALL(
2537 *context, 2524 *context,
2538 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); 2525 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
2539 EXPECT_CALL( 2526 EXPECT_CALL(
2540 *context, 2527 *context,
2541 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); 2528 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
2542 EXPECT_CALL(*context, 2529 EXPECT_CALL(*context,
2543 texParameteri(GL_TEXTURE_2D, 2530 texParameteri(GL_TEXTURE_2D,
2544 GL_TEXTURE_POOL_CHROMIUM, 2531 GL_TEXTURE_POOL_CHROMIUM,
2545 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM)); 2532 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM));
2546 // Check only TEXTURE_HINT_FRAMEBUFFER set GL_TEXTURE_USAGE_ANGLE. 2533 // Check only TextureHintFramebuffer set GL_TEXTURE_USAGE_ANGLE.
2547 bool is_framebuffer_hint = 2534 bool is_framebuffer_hint =
2548 hints[texture_id - 1] & ResourceProvider::TEXTURE_HINT_FRAMEBUFFER; 2535 hints[texture_id - 1] & ResourceProvider::TextureHintFramebuffer;
2549 EXPECT_CALL(*context, 2536 EXPECT_CALL(*context,
2550 texParameteri(GL_TEXTURE_2D, 2537 texParameteri(GL_TEXTURE_2D,
2551 GL_TEXTURE_USAGE_ANGLE, 2538 GL_TEXTURE_USAGE_ANGLE,
2552 GL_FRAMEBUFFER_ATTACHMENT_ANGLE)) 2539 GL_FRAMEBUFFER_ATTACHMENT_ANGLE))
2553 .Times(is_framebuffer_hint ? 1 : 0); 2540 .Times(is_framebuffer_hint ? 1 : 0);
2554 resource_provider->CreateForTesting(id); 2541 resource_provider->CreateForTesting(id);
2555 EXPECT_NE(0u, id); 2542 EXPECT_NE(0u, id);
2556 2543
2557 Mock::VerifyAndClearExpectations(context); 2544 Mock::VerifyAndClearExpectations(context);
2558 } 2545 }
2559 } 2546 }
2560 2547
2561 TEST_P(ResourceProviderTest, TextureMailbox_SharedMemory) { 2548 TEST_P(ResourceProviderTest, TextureMailbox_SharedMemory) {
2562 if (GetParam() != ResourceProvider::RESOURCE_TYPE_BITMAP) 2549 if (GetParam() != ResourceProvider::Bitmap)
2563 return; 2550 return;
2564 2551
2565 gfx::Size size(64, 64); 2552 gfx::Size size(64, 64);
2566 const uint32_t kBadBeef = 0xbadbeef; 2553 const uint32_t kBadBeef = 0xbadbeef;
2567 scoped_ptr<SharedBitmap> shared_bitmap( 2554 scoped_ptr<SharedBitmap> shared_bitmap(
2568 CreateAndFillSharedBitmap(shared_bitmap_manager_.get(), size, kBadBeef)); 2555 CreateAndFillSharedBitmap(shared_bitmap_manager_.get(), size, kBadBeef));
2569 2556
2570 FakeOutputSurfaceClient output_surface_client; 2557 FakeOutputSurfaceClient output_surface_client;
2571 scoped_ptr<OutputSurface> output_surface( 2558 scoped_ptr<OutputSurface> output_surface(
2572 FakeOutputSurface::CreateSoftware(make_scoped_ptr( 2559 FakeOutputSurface::CreateSoftware(make_scoped_ptr(
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
2706 2693
2707 resource_provider->DeleteResource(id); 2694 resource_provider->DeleteResource(id);
2708 EXPECT_EQ(0u, release_sync_point); 2695 EXPECT_EQ(0u, release_sync_point);
2709 EXPECT_FALSE(lost_resource); 2696 EXPECT_FALSE(lost_resource);
2710 EXPECT_EQ(main_thread_task_runner, mailbox_task_runner); 2697 EXPECT_EQ(main_thread_task_runner, mailbox_task_runner);
2711 } 2698 }
2712 }; 2699 };
2713 2700
2714 TEST_P(ResourceProviderTest, TextureMailbox_GLTexture2D_LinearToLinear) { 2701 TEST_P(ResourceProviderTest, TextureMailbox_GLTexture2D_LinearToLinear) {
2715 // Mailboxing is only supported for GL textures. 2702 // Mailboxing is only supported for GL textures.
2716 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 2703 if (GetParam() != ResourceProvider::GLTexture)
2717 return; 2704 return;
2718 2705
2719 ResourceProviderTestTextureMailboxGLFilters::RunTest( 2706 ResourceProviderTestTextureMailboxGLFilters::RunTest(
2720 shared_bitmap_manager_.get(), 2707 shared_bitmap_manager_.get(),
2721 gpu_memory_buffer_manager_.get(), 2708 gpu_memory_buffer_manager_.get(),
2722 main_thread_task_runner_.get(), 2709 main_thread_task_runner_.get(),
2723 false, 2710 false,
2724 GL_LINEAR); 2711 GL_LINEAR);
2725 } 2712 }
2726 2713
2727 TEST_P(ResourceProviderTest, TextureMailbox_GLTexture2D_NearestToNearest) { 2714 TEST_P(ResourceProviderTest, TextureMailbox_GLTexture2D_NearestToNearest) {
2728 // Mailboxing is only supported for GL textures. 2715 // Mailboxing is only supported for GL textures.
2729 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 2716 if (GetParam() != ResourceProvider::GLTexture)
2730 return; 2717 return;
2731 2718
2732 ResourceProviderTestTextureMailboxGLFilters::RunTest( 2719 ResourceProviderTestTextureMailboxGLFilters::RunTest(
2733 shared_bitmap_manager_.get(), 2720 shared_bitmap_manager_.get(),
2734 gpu_memory_buffer_manager_.get(), 2721 gpu_memory_buffer_manager_.get(),
2735 main_thread_task_runner_.get(), 2722 main_thread_task_runner_.get(),
2736 true, 2723 true,
2737 GL_NEAREST); 2724 GL_NEAREST);
2738 } 2725 }
2739 2726
2740 TEST_P(ResourceProviderTest, TextureMailbox_GLTexture2D_NearestToLinear) { 2727 TEST_P(ResourceProviderTest, TextureMailbox_GLTexture2D_NearestToLinear) {
2741 // Mailboxing is only supported for GL textures. 2728 // Mailboxing is only supported for GL textures.
2742 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 2729 if (GetParam() != ResourceProvider::GLTexture)
2743 return; 2730 return;
2744 2731
2745 ResourceProviderTestTextureMailboxGLFilters::RunTest( 2732 ResourceProviderTestTextureMailboxGLFilters::RunTest(
2746 shared_bitmap_manager_.get(), 2733 shared_bitmap_manager_.get(),
2747 gpu_memory_buffer_manager_.get(), 2734 gpu_memory_buffer_manager_.get(),
2748 main_thread_task_runner_.get(), 2735 main_thread_task_runner_.get(),
2749 true, 2736 true,
2750 GL_LINEAR); 2737 GL_LINEAR);
2751 } 2738 }
2752 2739
2753 TEST_P(ResourceProviderTest, TextureMailbox_GLTexture2D_LinearToNearest) { 2740 TEST_P(ResourceProviderTest, TextureMailbox_GLTexture2D_LinearToNearest) {
2754 // Mailboxing is only supported for GL textures. 2741 // Mailboxing is only supported for GL textures.
2755 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 2742 if (GetParam() != ResourceProvider::GLTexture)
2756 return; 2743 return;
2757 2744
2758 ResourceProviderTestTextureMailboxGLFilters::RunTest( 2745 ResourceProviderTestTextureMailboxGLFilters::RunTest(
2759 shared_bitmap_manager_.get(), 2746 shared_bitmap_manager_.get(),
2760 gpu_memory_buffer_manager_.get(), 2747 gpu_memory_buffer_manager_.get(),
2761 main_thread_task_runner_.get(), 2748 main_thread_task_runner_.get(),
2762 false, 2749 false,
2763 GL_NEAREST); 2750 GL_NEAREST);
2764 } 2751 }
2765 2752
2766 TEST_P(ResourceProviderTest, TextureMailbox_GLTextureExternalOES) { 2753 TEST_P(ResourceProviderTest, TextureMailbox_GLTextureExternalOES) {
2767 // Mailboxing is only supported for GL textures. 2754 // Mailboxing is only supported for GL textures.
2768 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 2755 if (GetParam() != ResourceProvider::GLTexture)
2769 return; 2756 return;
2770 2757
2771 scoped_ptr<TextureStateTrackingContext> context_owned( 2758 scoped_ptr<TextureStateTrackingContext> context_owned(
2772 new TextureStateTrackingContext); 2759 new TextureStateTrackingContext);
2773 TextureStateTrackingContext* context = context_owned.get(); 2760 TextureStateTrackingContext* context = context_owned.get();
2774 2761
2775 FakeOutputSurfaceClient output_surface_client; 2762 FakeOutputSurfaceClient output_surface_client;
2776 scoped_ptr<OutputSurface> output_surface( 2763 scoped_ptr<OutputSurface> output_surface(
2777 FakeOutputSurface::Create3d(context_owned.Pass())); 2764 FakeOutputSurface::Create3d(context_owned.Pass()));
2778 CHECK(output_surface->BindToClient(&output_surface_client)); 2765 CHECK(output_surface->BindToClient(&output_surface_client));
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
2833 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); 2820 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0);
2834 2821
2835 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); 2822 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0);
2836 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); 2823 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0);
2837 } 2824 }
2838 } 2825 }
2839 2826
2840 TEST_P(ResourceProviderTest, 2827 TEST_P(ResourceProviderTest,
2841 TextureMailbox_WaitSyncPointIfNeeded_WithSyncPoint) { 2828 TextureMailbox_WaitSyncPointIfNeeded_WithSyncPoint) {
2842 // Mailboxing is only supported for GL textures. 2829 // Mailboxing is only supported for GL textures.
2843 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 2830 if (GetParam() != ResourceProvider::GLTexture)
2844 return; 2831 return;
2845 2832
2846 scoped_ptr<TextureStateTrackingContext> context_owned( 2833 scoped_ptr<TextureStateTrackingContext> context_owned(
2847 new TextureStateTrackingContext); 2834 new TextureStateTrackingContext);
2848 TextureStateTrackingContext* context = context_owned.get(); 2835 TextureStateTrackingContext* context = context_owned.get();
2849 2836
2850 FakeOutputSurfaceClient output_surface_client; 2837 FakeOutputSurfaceClient output_surface_client;
2851 scoped_ptr<OutputSurface> output_surface( 2838 scoped_ptr<OutputSurface> output_surface(
2852 FakeOutputSurface::Create3d(context_owned.Pass())); 2839 FakeOutputSurface::Create3d(context_owned.Pass()));
2853 CHECK(output_surface->BindToClient(&output_surface_client)); 2840 CHECK(output_surface->BindToClient(&output_surface_client));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2892 2879
2893 // Subsequent calls to WaitSyncPointIfNeeded shouldn't call waitSyncPoint. 2880 // Subsequent calls to WaitSyncPointIfNeeded shouldn't call waitSyncPoint.
2894 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); 2881 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0);
2895 resource_provider->WaitSyncPointIfNeeded(id); 2882 resource_provider->WaitSyncPointIfNeeded(id);
2896 Mock::VerifyAndClearExpectations(context); 2883 Mock::VerifyAndClearExpectations(context);
2897 } 2884 }
2898 } 2885 }
2899 2886
2900 TEST_P(ResourceProviderTest, TextureMailbox_WaitSyncPointIfNeeded_NoSyncPoint) { 2887 TEST_P(ResourceProviderTest, TextureMailbox_WaitSyncPointIfNeeded_NoSyncPoint) {
2901 // Mailboxing is only supported for GL textures. 2888 // Mailboxing is only supported for GL textures.
2902 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 2889 if (GetParam() != ResourceProvider::GLTexture)
2903 return; 2890 return;
2904 2891
2905 scoped_ptr<TextureStateTrackingContext> context_owned( 2892 scoped_ptr<TextureStateTrackingContext> context_owned(
2906 new TextureStateTrackingContext); 2893 new TextureStateTrackingContext);
2907 TextureStateTrackingContext* context = context_owned.get(); 2894 TextureStateTrackingContext* context = context_owned.get();
2908 2895
2909 FakeOutputSurfaceClient output_surface_client; 2896 FakeOutputSurfaceClient output_surface_client;
2910 scoped_ptr<OutputSurface> output_surface( 2897 scoped_ptr<OutputSurface> output_surface(
2911 FakeOutputSurface::Create3d(context_owned.Pass())); 2898 FakeOutputSurface::Create3d(context_owned.Pass()));
2912 CHECK(output_surface->BindToClient(&output_surface_client)); 2899 CHECK(output_surface->BindToClient(&output_surface_client));
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
3019 MOCK_METHOD2(releaseTexImage2DCHROMIUM, void(GLenum, GLint)); 3006 MOCK_METHOD2(releaseTexImage2DCHROMIUM, void(GLenum, GLint));
3020 3007
3021 // We're mocking bindTexture, so we override 3008 // We're mocking bindTexture, so we override
3022 // TestWebGraphicsContext3D::texParameteri to avoid assertions related to the 3009 // TestWebGraphicsContext3D::texParameteri to avoid assertions related to the
3023 // currently bound texture. 3010 // currently bound texture.
3024 virtual void texParameteri(GLenum target, GLenum pname, GLint param) {} 3011 virtual void texParameteri(GLenum target, GLenum pname, GLint param) {}
3025 }; 3012 };
3026 3013
3027 TEST_P(ResourceProviderTest, TextureAllocation) { 3014 TEST_P(ResourceProviderTest, TextureAllocation) {
3028 // Only for GL textures. 3015 // Only for GL textures.
3029 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 3016 if (GetParam() != ResourceProvider::GLTexture)
3030 return; 3017 return;
3031 scoped_ptr<AllocationTrackingContext3D> context_owned( 3018 scoped_ptr<AllocationTrackingContext3D> context_owned(
3032 new StrictMock<AllocationTrackingContext3D>); 3019 new StrictMock<AllocationTrackingContext3D>);
3033 AllocationTrackingContext3D* context = context_owned.get(); 3020 AllocationTrackingContext3D* context = context_owned.get();
3034 3021
3035 FakeOutputSurfaceClient output_surface_client; 3022 FakeOutputSurfaceClient output_surface_client;
3036 scoped_ptr<OutputSurface> output_surface( 3023 scoped_ptr<OutputSurface> output_surface(
3037 FakeOutputSurface::Create3d(context_owned.Pass())); 3024 FakeOutputSurface::Create3d(context_owned.Pass()));
3038 CHECK(output_surface->BindToClient(&output_surface_client)); 3025 CHECK(output_surface->BindToClient(&output_surface_client));
3039 3026
3040 scoped_ptr<ResourceProvider> resource_provider( 3027 scoped_ptr<ResourceProvider> resource_provider(
3041 ResourceProvider::Create(output_surface.get(), 3028 ResourceProvider::Create(output_surface.get(),
3042 shared_bitmap_manager_.get(), 3029 shared_bitmap_manager_.get(),
3043 gpu_memory_buffer_manager_.get(), 3030 gpu_memory_buffer_manager_.get(),
3044 NULL, 3031 NULL,
3045 0, 3032 0,
3046 false, 3033 false,
3047 1)); 3034 1));
3048 3035
3049 gfx::Size size(2, 2); 3036 gfx::Size size(2, 2);
3050 gfx::Vector2d offset(0, 0); 3037 gfx::Vector2d offset(0, 0);
3038 gfx::Rect rect(0, 0, 2, 2);
3051 ResourceFormat format = RGBA_8888; 3039 ResourceFormat format = RGBA_8888;
3052 ResourceProvider::ResourceId id = 0; 3040 ResourceProvider::ResourceId id = 0;
3053 uint8_t pixels[16] = { 0 }; 3041 uint8_t pixels[16] = { 0 };
3054 int texture_id = 123; 3042 int texture_id = 123;
3055 3043
3056 // Lazy allocation. Don't allocate when creating the resource. 3044 // Lazy allocation. Don't allocate when creating the resource.
3057 id = resource_provider->CreateResource( 3045 id = resource_provider->CreateResource(
3058 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); 3046 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3059 3047
3060 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); 3048 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
3061 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1); 3049 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1);
3062 resource_provider->CreateForTesting(id); 3050 resource_provider->CreateForTesting(id);
3063 3051
3064 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); 3052 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1);
3065 resource_provider->DeleteResource(id); 3053 resource_provider->DeleteResource(id);
3066 3054
3067 Mock::VerifyAndClearExpectations(context); 3055 Mock::VerifyAndClearExpectations(context);
3068 3056
3069 // Do allocate when we set the pixels. 3057 // Do allocate when we set the pixels.
3070 id = resource_provider->CreateResource( 3058 id = resource_provider->CreateResource(
3071 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); 3059 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3072 3060
3073 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); 3061 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
3074 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(3); 3062 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(3);
3075 EXPECT_CALL(*context, texImage2D(_, _, _, 2, 2, _, _, _, _)).Times(1); 3063 EXPECT_CALL(*context, texImage2D(_, _, _, 2, 2, _, _, _, _)).Times(1);
3076 EXPECT_CALL(*context, texSubImage2D(_, _, _, _, 2, 2, _, _, _)).Times(1); 3064 EXPECT_CALL(*context, texSubImage2D(_, _, _, _, 2, 2, _, _, _)).Times(1);
3077 resource_provider->CopyToResource(id, pixels, size); 3065 resource_provider->SetPixels(id, pixels, rect, rect, offset);
3078 3066
3079 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); 3067 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1);
3080 resource_provider->DeleteResource(id); 3068 resource_provider->DeleteResource(id);
3081 3069
3082 Mock::VerifyAndClearExpectations(context); 3070 Mock::VerifyAndClearExpectations(context);
3083 3071
3084 // Same for async version. 3072 // Same for async version.
3085 id = resource_provider->CreateResource( 3073 id = resource_provider->CreateResource(
3086 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); 3074 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3087 resource_provider->AcquirePixelBuffer(id); 3075 resource_provider->AcquirePixelBuffer(id);
3088 3076
3089 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); 3077 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
3090 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); 3078 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2);
3091 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) 3079 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _))
3092 .Times(1); 3080 .Times(1);
3093 resource_provider->BeginSetPixels(id); 3081 resource_provider->BeginSetPixels(id);
3094 ASSERT_TRUE(resource_provider->DidSetPixelsComplete(id)); 3082 ASSERT_TRUE(resource_provider->DidSetPixelsComplete(id));
3095 3083
3096 resource_provider->ReleasePixelBuffer(id); 3084 resource_provider->ReleasePixelBuffer(id);
3097 3085
3098 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); 3086 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1);
3099 resource_provider->DeleteResource(id); 3087 resource_provider->DeleteResource(id);
3100 3088
3101 Mock::VerifyAndClearExpectations(context); 3089 Mock::VerifyAndClearExpectations(context);
3102 } 3090 }
3103 3091
3104 TEST_P(ResourceProviderTest, TextureAllocationHint) { 3092 TEST_P(ResourceProviderTest, TextureAllocationHint) {
3105 // Only for GL textures. 3093 // Only for GL textures.
3106 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 3094 if (GetParam() != ResourceProvider::GLTexture)
3107 return; 3095 return;
3108 scoped_ptr<AllocationTrackingContext3D> context_owned( 3096 scoped_ptr<AllocationTrackingContext3D> context_owned(
3109 new StrictMock<AllocationTrackingContext3D>); 3097 new StrictMock<AllocationTrackingContext3D>);
3110 AllocationTrackingContext3D* context = context_owned.get(); 3098 AllocationTrackingContext3D* context = context_owned.get();
3111 context->set_support_texture_storage(true); 3099 context->set_support_texture_storage(true);
3112 context->set_support_texture_usage(true); 3100 context->set_support_texture_usage(true);
3113 3101
3114 FakeOutputSurfaceClient output_surface_client; 3102 FakeOutputSurfaceClient output_surface_client;
3115 scoped_ptr<OutputSurface> output_surface( 3103 scoped_ptr<OutputSurface> output_surface(
3116 FakeOutputSurface::Create3d(context_owned.Pass())); 3104 FakeOutputSurface::Create3d(context_owned.Pass()));
3117 CHECK(output_surface->BindToClient(&output_surface_client)); 3105 CHECK(output_surface->BindToClient(&output_surface_client));
3118 3106
3119 scoped_ptr<ResourceProvider> resource_provider( 3107 scoped_ptr<ResourceProvider> resource_provider(
3120 ResourceProvider::Create(output_surface.get(), 3108 ResourceProvider::Create(output_surface.get(),
3121 shared_bitmap_manager_.get(), 3109 shared_bitmap_manager_.get(),
3122 gpu_memory_buffer_manager_.get(), 3110 gpu_memory_buffer_manager_.get(),
3123 NULL, 3111 NULL,
3124 0, 3112 0,
3125 false, 3113 false,
3126 1)); 3114 1));
3127 3115
3128 gfx::Size size(2, 2); 3116 gfx::Size size(2, 2);
3129 3117
3130 const ResourceFormat formats[2] = {RGBA_8888, BGRA_8888}; 3118 const ResourceFormat formats[2] = {RGBA_8888, BGRA_8888};
3131 const ResourceProvider::TextureHint hints[4] = { 3119 const ResourceProvider::TextureHint hints[4] = {
3132 ResourceProvider::TEXTURE_HINT_DEFAULT, 3120 ResourceProvider::TextureHintDefault,
3133 ResourceProvider::TEXTURE_HINT_IMMUTABLE, 3121 ResourceProvider::TextureHintImmutable,
3134 ResourceProvider::TEXTURE_HINT_FRAMEBUFFER, 3122 ResourceProvider::TextureHintFramebuffer,
3135 ResourceProvider::TEXTURE_HINT_IMMUTABLE_FRAMEBUFFER, 3123 ResourceProvider::TextureHintImmutableFramebuffer,
3136 }; 3124 };
3137 for (size_t i = 0; i < arraysize(formats); ++i) { 3125 for (size_t i = 0; i < arraysize(formats); ++i) {
3138 for (GLuint texture_id = 1; texture_id <= arraysize(hints); ++texture_id) { 3126 for (GLuint texture_id = 1; texture_id <= arraysize(hints); ++texture_id) {
3139 // Lazy allocation. Don't allocate when creating the resource. 3127 // Lazy allocation. Don't allocate when creating the resource.
3140 ResourceProvider::ResourceId id = resource_provider->CreateResource( 3128 ResourceProvider::ResourceId id = resource_provider->CreateResource(
3141 size, GL_CLAMP_TO_EDGE, hints[texture_id - 1], formats[i]); 3129 size, GL_CLAMP_TO_EDGE, hints[texture_id - 1], formats[i]);
3142 3130
3143 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); 3131 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
3144 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); 3132 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2);
3145 bool is_immutable_hint = 3133 bool is_immutable_hint =
3146 hints[texture_id - 1] & ResourceProvider::TEXTURE_HINT_IMMUTABLE; 3134 hints[texture_id - 1] & ResourceProvider::TextureHintImmutable;
3147 bool support_immutable_texture = 3135 bool support_immutable_texture =
3148 is_immutable_hint && formats[i] == RGBA_8888; 3136 is_immutable_hint && formats[i] == RGBA_8888;
3149 EXPECT_CALL(*context, texStorage2DEXT(_, _, _, 2, 2)) 3137 EXPECT_CALL(*context, texStorage2DEXT(_, _, _, 2, 2))
3150 .Times(support_immutable_texture ? 1 : 0); 3138 .Times(support_immutable_texture ? 1 : 0);
3151 EXPECT_CALL(*context, texImage2D(_, _, _, 2, 2, _, _, _, _)) 3139 EXPECT_CALL(*context, texImage2D(_, _, _, 2, 2, _, _, _, _))
3152 .Times(support_immutable_texture ? 0 : 1); 3140 .Times(support_immutable_texture ? 0 : 1);
3153 resource_provider->AllocateForTesting(id); 3141 resource_provider->AllocateForTesting(id);
3154 3142
3155 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); 3143 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1);
3156 resource_provider->DeleteResource(id); 3144 resource_provider->DeleteResource(id);
3157 3145
3158 Mock::VerifyAndClearExpectations(context); 3146 Mock::VerifyAndClearExpectations(context);
3159 } 3147 }
3160 } 3148 }
3161 } 3149 }
3162 3150
3163 TEST_P(ResourceProviderTest, TextureAllocationHint_BGRA) { 3151 TEST_P(ResourceProviderTest, TextureAllocationHint_BGRA) {
3164 // Only for GL textures. 3152 // Only for GL textures.
3165 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 3153 if (GetParam() != ResourceProvider::GLTexture)
3166 return; 3154 return;
3167 scoped_ptr<AllocationTrackingContext3D> context_owned( 3155 scoped_ptr<AllocationTrackingContext3D> context_owned(
3168 new StrictMock<AllocationTrackingContext3D>); 3156 new StrictMock<AllocationTrackingContext3D>);
3169 AllocationTrackingContext3D* context = context_owned.get(); 3157 AllocationTrackingContext3D* context = context_owned.get();
3170 context->set_support_texture_format_bgra8888(true); 3158 context->set_support_texture_format_bgra8888(true);
3171 context->set_support_texture_storage(true); 3159 context->set_support_texture_storage(true);
3172 context->set_support_texture_usage(true); 3160 context->set_support_texture_usage(true);
3173 3161
3174 FakeOutputSurfaceClient output_surface_client; 3162 FakeOutputSurfaceClient output_surface_client;
3175 scoped_ptr<OutputSurface> output_surface( 3163 scoped_ptr<OutputSurface> output_surface(
3176 FakeOutputSurface::Create3d(context_owned.Pass())); 3164 FakeOutputSurface::Create3d(context_owned.Pass()));
3177 CHECK(output_surface->BindToClient(&output_surface_client)); 3165 CHECK(output_surface->BindToClient(&output_surface_client));
3178 3166
3179 scoped_ptr<ResourceProvider> resource_provider( 3167 scoped_ptr<ResourceProvider> resource_provider(
3180 ResourceProvider::Create(output_surface.get(), 3168 ResourceProvider::Create(output_surface.get(),
3181 shared_bitmap_manager_.get(), 3169 shared_bitmap_manager_.get(),
3182 gpu_memory_buffer_manager_.get(), 3170 gpu_memory_buffer_manager_.get(),
3183 NULL, 3171 NULL,
3184 0, 3172 0,
3185 false, 3173 false,
3186 1)); 3174 1));
3187 3175
3188 gfx::Size size(2, 2); 3176 gfx::Size size(2, 2);
3189 const ResourceFormat formats[2] = {RGBA_8888, BGRA_8888}; 3177 const ResourceFormat formats[2] = {RGBA_8888, BGRA_8888};
3190 3178
3191 const ResourceProvider::TextureHint hints[4] = { 3179 const ResourceProvider::TextureHint hints[4] = {
3192 ResourceProvider::TEXTURE_HINT_DEFAULT, 3180 ResourceProvider::TextureHintDefault,
3193 ResourceProvider::TEXTURE_HINT_IMMUTABLE, 3181 ResourceProvider::TextureHintImmutable,
3194 ResourceProvider::TEXTURE_HINT_FRAMEBUFFER, 3182 ResourceProvider::TextureHintFramebuffer,
3195 ResourceProvider::TEXTURE_HINT_IMMUTABLE_FRAMEBUFFER, 3183 ResourceProvider::TextureHintImmutableFramebuffer,
3196 }; 3184 };
3197 for (size_t i = 0; i < arraysize(formats); ++i) { 3185 for (size_t i = 0; i < arraysize(formats); ++i) {
3198 for (GLuint texture_id = 1; texture_id <= arraysize(hints); ++texture_id) { 3186 for (GLuint texture_id = 1; texture_id <= arraysize(hints); ++texture_id) {
3199 // Lazy allocation. Don't allocate when creating the resource. 3187 // Lazy allocation. Don't allocate when creating the resource.
3200 ResourceProvider::ResourceId id = resource_provider->CreateResource( 3188 ResourceProvider::ResourceId id = resource_provider->CreateResource(
3201 size, GL_CLAMP_TO_EDGE, hints[texture_id - 1], formats[i]); 3189 size, GL_CLAMP_TO_EDGE, hints[texture_id - 1], formats[i]);
3202 3190
3203 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); 3191 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
3204 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); 3192 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2);
3205 bool is_immutable_hint = 3193 bool is_immutable_hint =
3206 hints[texture_id - 1] & ResourceProvider::TEXTURE_HINT_IMMUTABLE; 3194 hints[texture_id - 1] & ResourceProvider::TextureHintImmutable;
3207 EXPECT_CALL(*context, texStorage2DEXT(_, _, _, 2, 2)) 3195 EXPECT_CALL(*context, texStorage2DEXT(_, _, _, 2, 2))
3208 .Times(is_immutable_hint ? 1 : 0); 3196 .Times(is_immutable_hint ? 1 : 0);
3209 EXPECT_CALL(*context, texImage2D(_, _, _, 2, 2, _, _, _, _)) 3197 EXPECT_CALL(*context, texImage2D(_, _, _, 2, 2, _, _, _, _))
3210 .Times(is_immutable_hint ? 0 : 1); 3198 .Times(is_immutable_hint ? 0 : 1);
3211 resource_provider->AllocateForTesting(id); 3199 resource_provider->AllocateForTesting(id);
3212 3200
3213 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); 3201 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1);
3214 resource_provider->DeleteResource(id); 3202 resource_provider->DeleteResource(id);
3215 3203
3216 Mock::VerifyAndClearExpectations(context); 3204 Mock::VerifyAndClearExpectations(context);
3217 } 3205 }
3218 } 3206 }
3219 } 3207 }
3220 3208
3221 TEST_P(ResourceProviderTest, PixelBuffer_GLTexture) { 3209 TEST_P(ResourceProviderTest, PixelBuffer_GLTexture) {
3222 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 3210 if (GetParam() != ResourceProvider::GLTexture)
3223 return; 3211 return;
3224 scoped_ptr<AllocationTrackingContext3D> context_owned( 3212 scoped_ptr<AllocationTrackingContext3D> context_owned(
3225 new StrictMock<AllocationTrackingContext3D>); 3213 new StrictMock<AllocationTrackingContext3D>);
3226 AllocationTrackingContext3D* context = context_owned.get(); 3214 AllocationTrackingContext3D* context = context_owned.get();
3227 3215
3228 FakeOutputSurfaceClient output_surface_client; 3216 FakeOutputSurfaceClient output_surface_client;
3229 scoped_ptr<OutputSurface> output_surface( 3217 scoped_ptr<OutputSurface> output_surface(
3230 FakeOutputSurface::Create3d(context_owned.Pass())); 3218 FakeOutputSurface::Create3d(context_owned.Pass()));
3231 CHECK(output_surface->BindToClient(&output_surface_client)); 3219 CHECK(output_surface->BindToClient(&output_surface_client));
3232 3220
3233 gfx::Size size(2, 2); 3221 gfx::Size size(2, 2);
3234 ResourceFormat format = RGBA_8888; 3222 ResourceFormat format = RGBA_8888;
3235 ResourceProvider::ResourceId id = 0; 3223 ResourceProvider::ResourceId id = 0;
3236 int texture_id = 123; 3224 int texture_id = 123;
3237 3225
3238 scoped_ptr<ResourceProvider> resource_provider( 3226 scoped_ptr<ResourceProvider> resource_provider(
3239 ResourceProvider::Create(output_surface.get(), 3227 ResourceProvider::Create(output_surface.get(),
3240 shared_bitmap_manager_.get(), 3228 shared_bitmap_manager_.get(),
3241 gpu_memory_buffer_manager_.get(), 3229 gpu_memory_buffer_manager_.get(),
3242 NULL, 3230 NULL,
3243 0, 3231 0,
3244 false, 3232 false,
3245 1)); 3233 1));
3246 3234
3247 id = resource_provider->CreateResource( 3235 id = resource_provider->CreateResource(
3248 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); 3236 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3249 resource_provider->AcquirePixelBuffer(id); 3237 resource_provider->AcquirePixelBuffer(id);
3250 3238
3251 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); 3239 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
3252 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); 3240 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2);
3253 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) 3241 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _))
3254 .Times(1); 3242 .Times(1);
3255 resource_provider->BeginSetPixels(id); 3243 resource_provider->BeginSetPixels(id);
3256 3244
3257 EXPECT_TRUE(resource_provider->DidSetPixelsComplete(id)); 3245 EXPECT_TRUE(resource_provider->DidSetPixelsComplete(id));
3258 3246
3259 resource_provider->ReleasePixelBuffer(id); 3247 resource_provider->ReleasePixelBuffer(id);
3260 3248
3261 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); 3249 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1);
3262 resource_provider->DeleteResource(id); 3250 resource_provider->DeleteResource(id);
3263 3251
3264 Mock::VerifyAndClearExpectations(context); 3252 Mock::VerifyAndClearExpectations(context);
3265 } 3253 }
3266 3254
3267 TEST_P(ResourceProviderTest, ForcingAsyncUploadToComplete) { 3255 TEST_P(ResourceProviderTest, ForcingAsyncUploadToComplete) {
3268 // Only for GL textures. 3256 // Only for GL textures.
3269 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 3257 if (GetParam() != ResourceProvider::GLTexture)
3270 return; 3258 return;
3271 scoped_ptr<AllocationTrackingContext3D> context_owned( 3259 scoped_ptr<AllocationTrackingContext3D> context_owned(
3272 new StrictMock<AllocationTrackingContext3D>); 3260 new StrictMock<AllocationTrackingContext3D>);
3273 AllocationTrackingContext3D* context = context_owned.get(); 3261 AllocationTrackingContext3D* context = context_owned.get();
3274 3262
3275 FakeOutputSurfaceClient output_surface_client; 3263 FakeOutputSurfaceClient output_surface_client;
3276 scoped_ptr<OutputSurface> output_surface( 3264 scoped_ptr<OutputSurface> output_surface(
3277 FakeOutputSurface::Create3d(context_owned.Pass())); 3265 FakeOutputSurface::Create3d(context_owned.Pass()));
3278 CHECK(output_surface->BindToClient(&output_surface_client)); 3266 CHECK(output_surface->BindToClient(&output_surface_client));
3279 3267
3280 gfx::Size size(2, 2); 3268 gfx::Size size(2, 2);
3281 ResourceFormat format = RGBA_8888; 3269 ResourceFormat format = RGBA_8888;
3282 ResourceProvider::ResourceId id = 0; 3270 ResourceProvider::ResourceId id = 0;
3283 int texture_id = 123; 3271 int texture_id = 123;
3284 3272
3285 scoped_ptr<ResourceProvider> resource_provider( 3273 scoped_ptr<ResourceProvider> resource_provider(
3286 ResourceProvider::Create(output_surface.get(), 3274 ResourceProvider::Create(output_surface.get(),
3287 shared_bitmap_manager_.get(), 3275 shared_bitmap_manager_.get(),
3288 gpu_memory_buffer_manager_.get(), 3276 gpu_memory_buffer_manager_.get(),
3289 NULL, 3277 NULL,
3290 0, 3278 0,
3291 false, 3279 false,
3292 1)); 3280 1));
3293 3281
3294 id = resource_provider->CreateResource( 3282 id = resource_provider->CreateResource(
3295 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); 3283 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3296 resource_provider->AcquirePixelBuffer(id); 3284 resource_provider->AcquirePixelBuffer(id);
3297 3285
3298 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); 3286 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
3299 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); 3287 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2);
3300 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) 3288 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _))
3301 .Times(1); 3289 .Times(1);
3302 resource_provider->BeginSetPixels(id); 3290 resource_provider->BeginSetPixels(id);
3303 3291
3304 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1); 3292 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1);
3305 EXPECT_CALL(*context, waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)).Times(1); 3293 EXPECT_CALL(*context, waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)).Times(1);
(...skipping 28 matching lines...) Expand all
3334 shared_bitmap_manager_.get(), 3322 shared_bitmap_manager_.get(),
3335 gpu_memory_buffer_manager_.get(), 3323 gpu_memory_buffer_manager_.get(),
3336 NULL, 3324 NULL,
3337 0, 3325 0,
3338 false, 3326 false,
3339 1)); 3327 1));
3340 3328
3341 EXPECT_CALL(*context, NextTextureId()).WillRepeatedly(Return(texture_id)); 3329 EXPECT_CALL(*context, NextTextureId()).WillRepeatedly(Return(texture_id));
3342 3330
3343 id = resource_provider->CreateResource( 3331 id = resource_provider->CreateResource(
3344 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); 3332 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3345 context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, 3333 context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
3346 GL_INNOCENT_CONTEXT_RESET_ARB); 3334 GL_INNOCENT_CONTEXT_RESET_ARB);
3347 3335
3348 resource_provider->AcquirePixelBuffer(id); 3336 resource_provider->AcquirePixelBuffer(id);
3349 int stride; 3337 int stride;
3350 void* buffer = resource_provider->MapPixelBuffer(id, &stride); 3338 void* buffer = resource_provider->MapPixelBuffer(id, &stride);
3351 EXPECT_FALSE(buffer); 3339 EXPECT_FALSE(buffer);
3352 resource_provider->UnmapPixelBuffer(id); 3340 resource_provider->UnmapPixelBuffer(id);
3353 Mock::VerifyAndClearExpectations(context); 3341 Mock::VerifyAndClearExpectations(context);
3354 } 3342 }
3355 3343
3356 TEST_P(ResourceProviderTest, Image_GLTexture) { 3344 TEST_P(ResourceProviderTest, Image_GLTexture) {
3357 // Only for GL textures. 3345 // Only for GL textures.
3358 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 3346 if (GetParam() != ResourceProvider::GLTexture)
3359 return; 3347 return;
3360 scoped_ptr<AllocationTrackingContext3D> context_owned( 3348 scoped_ptr<AllocationTrackingContext3D> context_owned(
3361 new StrictMock<AllocationTrackingContext3D>); 3349 new StrictMock<AllocationTrackingContext3D>);
3362 AllocationTrackingContext3D* context = context_owned.get(); 3350 AllocationTrackingContext3D* context = context_owned.get();
3363 3351
3364 FakeOutputSurfaceClient output_surface_client; 3352 FakeOutputSurfaceClient output_surface_client;
3365 scoped_ptr<OutputSurface> output_surface( 3353 scoped_ptr<OutputSurface> output_surface(
3366 FakeOutputSurface::Create3d(context_owned.Pass())); 3354 FakeOutputSurface::Create3d(context_owned.Pass()));
3367 CHECK(output_surface->BindToClient(&output_surface_client)); 3355 CHECK(output_surface->BindToClient(&output_surface_client));
3368 3356
3369 const int kWidth = 2; 3357 const int kWidth = 2;
3370 const int kHeight = 2; 3358 const int kHeight = 2;
3371 gfx::Size size(kWidth, kHeight); 3359 gfx::Size size(kWidth, kHeight);
3372 ResourceFormat format = RGBA_8888; 3360 ResourceFormat format = RGBA_8888;
3373 ResourceProvider::ResourceId id = 0; 3361 ResourceProvider::ResourceId id = 0;
3374 const unsigned kTextureId = 123u; 3362 const unsigned kTextureId = 123u;
3375 const unsigned kImageId = 234u; 3363 const unsigned kImageId = 234u;
3376 3364
3377 scoped_ptr<ResourceProvider> resource_provider( 3365 scoped_ptr<ResourceProvider> resource_provider(
3378 ResourceProvider::Create(output_surface.get(), 3366 ResourceProvider::Create(output_surface.get(),
3379 shared_bitmap_manager_.get(), 3367 shared_bitmap_manager_.get(),
3380 gpu_memory_buffer_manager_.get(), 3368 gpu_memory_buffer_manager_.get(),
3381 NULL, 3369 NULL,
3382 0, 3370 0,
3383 false, 3371 false,
3384 1)); 3372 1));
3385 3373
3386 id = resource_provider->CreateResource( 3374 id = resource_provider->CreateResource(
3387 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); 3375 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3388 3376
3389 EXPECT_CALL(*context, createImageCHROMIUM(_, kWidth, kHeight, GL_RGBA)) 3377 EXPECT_CALL(*context, createImageCHROMIUM(_, kWidth, kHeight, GL_RGBA))
3390 .WillOnce(Return(kImageId)) 3378 .WillOnce(Return(kImageId))
3391 .RetiresOnSaturation(); 3379 .RetiresOnSaturation();
3392 { 3380 {
3393 ResourceProvider::ScopedWriteLockGpuMemoryBuffer lock( 3381 ResourceProvider::ScopedWriteLockGpuMemoryBuffer lock(
3394 resource_provider.get(), id); 3382 resource_provider.get(), id);
3395 EXPECT_TRUE(!!lock.GetGpuMemoryBuffer()); 3383 EXPECT_TRUE(!!lock.GetGpuMemoryBuffer());
3396 } 3384 }
3397 3385
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
3432 resource_provider.get(), id, GL_TEXTURE_2D, GL_LINEAR); 3420 resource_provider.get(), id, GL_TEXTURE_2D, GL_LINEAR);
3433 EXPECT_EQ(kTextureId, lock_gl.texture_id()); 3421 EXPECT_EQ(kTextureId, lock_gl.texture_id());
3434 } 3422 }
3435 3423
3436 EXPECT_CALL(*context, destroyImageCHROMIUM(kImageId)) 3424 EXPECT_CALL(*context, destroyImageCHROMIUM(kImageId))
3437 .Times(1) 3425 .Times(1)
3438 .RetiresOnSaturation(); 3426 .RetiresOnSaturation();
3439 } 3427 }
3440 3428
3441 TEST_P(ResourceProviderTest, CopyResource_GLTexture) { 3429 TEST_P(ResourceProviderTest, CopyResource_GLTexture) {
3442 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 3430 if (GetParam() != ResourceProvider::GLTexture)
3443 return; 3431 return;
3444 scoped_ptr<AllocationTrackingContext3D> context_owned( 3432 scoped_ptr<AllocationTrackingContext3D> context_owned(
3445 new StrictMock<AllocationTrackingContext3D>); 3433 new StrictMock<AllocationTrackingContext3D>);
3446 AllocationTrackingContext3D* context = context_owned.get(); 3434 AllocationTrackingContext3D* context = context_owned.get();
3447 context_owned->set_support_sync_query(true); 3435 context_owned->set_support_sync_query(true);
3448 3436
3449 FakeOutputSurfaceClient output_surface_client; 3437 FakeOutputSurfaceClient output_surface_client;
3450 scoped_ptr<OutputSurface> output_surface( 3438 scoped_ptr<OutputSurface> output_surface(
3451 FakeOutputSurface::Create3d(context_owned.Pass())); 3439 FakeOutputSurface::Create3d(context_owned.Pass()));
3452 ASSERT_TRUE(output_surface->BindToClient(&output_surface_client)); 3440 ASSERT_TRUE(output_surface->BindToClient(&output_surface_client));
(...skipping 11 matching lines...) Expand all
3464 scoped_ptr<ResourceProvider> resource_provider( 3452 scoped_ptr<ResourceProvider> resource_provider(
3465 ResourceProvider::Create(output_surface.get(), 3453 ResourceProvider::Create(output_surface.get(),
3466 shared_bitmap_manager_.get(), 3454 shared_bitmap_manager_.get(),
3467 gpu_memory_buffer_manager_.get(), 3455 gpu_memory_buffer_manager_.get(),
3468 NULL, 3456 NULL,
3469 0, 3457 0,
3470 false, 3458 false,
3471 1)); 3459 1));
3472 3460
3473 source_id = resource_provider->CreateResource( 3461 source_id = resource_provider->CreateResource(
3474 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); 3462 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3475 3463
3476 EXPECT_CALL(*context, createImageCHROMIUM(_, kWidth, kHeight, GL_RGBA)) 3464 EXPECT_CALL(*context, createImageCHROMIUM(_, kWidth, kHeight, GL_RGBA))
3477 .WillOnce(Return(kImageId)) 3465 .WillOnce(Return(kImageId))
3478 .RetiresOnSaturation(); 3466 .RetiresOnSaturation();
3479 { 3467 {
3480 ResourceProvider::ScopedWriteLockGpuMemoryBuffer lock( 3468 ResourceProvider::ScopedWriteLockGpuMemoryBuffer lock(
3481 resource_provider.get(), source_id); 3469 resource_provider.get(), source_id);
3482 EXPECT_TRUE(!!lock.GetGpuMemoryBuffer()); 3470 EXPECT_TRUE(!!lock.GetGpuMemoryBuffer());
3483 } 3471 }
3484 Mock::VerifyAndClearExpectations(context); 3472 Mock::VerifyAndClearExpectations(context);
3485 3473
3486 dest_id = resource_provider->CreateResource( 3474 dest_id = resource_provider->CreateResource(
3487 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); 3475 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3488 3476
3489 EXPECT_CALL(*context, NextTextureId()) 3477 EXPECT_CALL(*context, NextTextureId())
3490 .WillOnce(Return(kDestTextureId)) 3478 .WillOnce(Return(kDestTextureId))
3491 .RetiresOnSaturation(); 3479 .RetiresOnSaturation();
3492 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kDestTextureId)) 3480 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kDestTextureId))
3493 .Times(2) 3481 .Times(2)
3494 .RetiresOnSaturation(); 3482 .RetiresOnSaturation();
3495 EXPECT_CALL(*context, texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, 3483 EXPECT_CALL(*context, texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA,
3496 GL_UNSIGNED_BYTE, nullptr)) 3484 GL_UNSIGNED_BYTE, nullptr))
3497 .Times(1) 3485 .Times(1)
(...skipping 28 matching lines...) Expand all
3526 FakeOutputSurface* output_surface) { 3514 FakeOutputSurface* output_surface) {
3527 scoped_ptr<ResourceProviderContext> context_owned = 3515 scoped_ptr<ResourceProviderContext> context_owned =
3528 ResourceProviderContext::Create(shared_data); 3516 ResourceProviderContext::Create(shared_data);
3529 ResourceProviderContext* context = context_owned.get(); 3517 ResourceProviderContext* context = context_owned.get();
3530 3518
3531 scoped_refptr<TestContextProvider> context_provider = 3519 scoped_refptr<TestContextProvider> context_provider =
3532 TestContextProvider::Create(context_owned.Pass()); 3520 TestContextProvider::Create(context_owned.Pass());
3533 output_surface->InitializeAndSetContext3d(context_provider, nullptr); 3521 output_surface->InitializeAndSetContext3d(context_provider, nullptr);
3534 resource_provider->InitializeGL(); 3522 resource_provider->InitializeGL();
3535 3523
3536 CheckCreateResource(ResourceProvider::RESOURCE_TYPE_GL_TEXTURE, 3524 CheckCreateResource(ResourceProvider::GLTexture, resource_provider, context);
3537 resource_provider, context);
3538 } 3525 }
3539 3526
3540 TEST(ResourceProviderTest, BasicInitializeGLSoftware) { 3527 TEST(ResourceProviderTest, BasicInitializeGLSoftware) {
3541 scoped_ptr<ContextSharedData> shared_data = ContextSharedData::Create(); 3528 scoped_ptr<ContextSharedData> shared_data = ContextSharedData::Create();
3542 bool delegated_rendering = false; 3529 bool delegated_rendering = false;
3543 scoped_ptr<FakeOutputSurface> output_surface( 3530 scoped_ptr<FakeOutputSurface> output_surface(
3544 FakeOutputSurface::CreateDeferredGL( 3531 FakeOutputSurface::CreateDeferredGL(
3545 scoped_ptr<SoftwareOutputDevice>(new SoftwareOutputDevice), 3532 scoped_ptr<SoftwareOutputDevice>(new SoftwareOutputDevice),
3546 delegated_rendering)); 3533 delegated_rendering));
3547 FakeOutputSurfaceClient client(output_surface.get()); 3534 FakeOutputSurfaceClient client(output_surface.get());
3548 EXPECT_TRUE(output_surface->BindToClient(&client)); 3535 EXPECT_TRUE(output_surface->BindToClient(&client));
3549 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( 3536 scoped_ptr<SharedBitmapManager> shared_bitmap_manager(
3550 new TestSharedBitmapManager()); 3537 new TestSharedBitmapManager());
3551 scoped_ptr<ResourceProvider> resource_provider( 3538 scoped_ptr<ResourceProvider> resource_provider(
3552 ResourceProvider::Create(output_surface.get(), 3539 ResourceProvider::Create(output_surface.get(),
3553 shared_bitmap_manager.get(), 3540 shared_bitmap_manager.get(),
3554 NULL, 3541 NULL,
3555 NULL, 3542 NULL,
3556 0, 3543 0,
3557 false, 3544 false,
3558 1)); 3545 1));
3559 3546
3560 CheckCreateResource(ResourceProvider::RESOURCE_TYPE_BITMAP, 3547 CheckCreateResource(ResourceProvider::Bitmap, resource_provider.get(), NULL);
3561 resource_provider.get(), NULL);
3562 3548
3563 InitializeGLAndCheck(shared_data.get(), 3549 InitializeGLAndCheck(shared_data.get(),
3564 resource_provider.get(), 3550 resource_provider.get(),
3565 output_surface.get()); 3551 output_surface.get());
3566 3552
3567 resource_provider->InitializeSoftware(); 3553 resource_provider->InitializeSoftware();
3568 output_surface->ReleaseGL(); 3554 output_surface->ReleaseGL();
3569 CheckCreateResource(ResourceProvider::RESOURCE_TYPE_BITMAP, 3555 CheckCreateResource(ResourceProvider::Bitmap, resource_provider.get(), NULL);
3570 resource_provider.get(), NULL);
3571 3556
3572 InitializeGLAndCheck(shared_data.get(), 3557 InitializeGLAndCheck(shared_data.get(),
3573 resource_provider.get(), 3558 resource_provider.get(),
3574 output_surface.get()); 3559 output_surface.get());
3575 } 3560 }
3576 3561
3577 TEST_P(ResourceProviderTest, CompressedTextureETC1Allocate) { 3562 TEST_P(ResourceProviderTest, CompressedTextureETC1Allocate) {
3578 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 3563 if (GetParam() != ResourceProvider::GLTexture)
3579 return; 3564 return;
3580 3565
3581 scoped_ptr<AllocationTrackingContext3D> context_owned( 3566 scoped_ptr<AllocationTrackingContext3D> context_owned(
3582 new AllocationTrackingContext3D); 3567 new AllocationTrackingContext3D);
3583 AllocationTrackingContext3D* context = context_owned.get(); 3568 AllocationTrackingContext3D* context = context_owned.get();
3584 context_owned->set_support_compressed_texture_etc1(true); 3569 context_owned->set_support_compressed_texture_etc1(true);
3585 3570
3586 FakeOutputSurfaceClient output_surface_client; 3571 FakeOutputSurfaceClient output_surface_client;
3587 scoped_ptr<OutputSurface> output_surface( 3572 scoped_ptr<OutputSurface> output_surface(
3588 FakeOutputSurface::Create3d(context_owned.Pass())); 3573 FakeOutputSurface::Create3d(context_owned.Pass()));
3589 CHECK(output_surface->BindToClient(&output_surface_client)); 3574 CHECK(output_surface->BindToClient(&output_surface_client));
3590 3575
3591 gfx::Size size(4, 4); 3576 gfx::Size size(4, 4);
3592 scoped_ptr<ResourceProvider> resource_provider( 3577 scoped_ptr<ResourceProvider> resource_provider(
3593 ResourceProvider::Create(output_surface.get(), 3578 ResourceProvider::Create(output_surface.get(),
3594 shared_bitmap_manager_.get(), 3579 shared_bitmap_manager_.get(),
3595 gpu_memory_buffer_manager_.get(), 3580 gpu_memory_buffer_manager_.get(),
3596 NULL, 3581 NULL,
3597 0, 3582 0,
3598 false, 3583 false,
3599 1)); 3584 1));
3600 int texture_id = 123; 3585 int texture_id = 123;
3601 3586
3602 ResourceProvider::ResourceId id = resource_provider->CreateResource( 3587 ResourceProvider::ResourceId id = resource_provider->CreateResource(
3603 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, ETC1); 3588 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, ETC1);
3604 EXPECT_NE(0u, id); 3589 EXPECT_NE(0u, id);
3605 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); 3590 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
3606 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); 3591 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2);
3607 resource_provider->AllocateForTesting(id); 3592 resource_provider->AllocateForTesting(id);
3608 3593
3609 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); 3594 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1);
3610 resource_provider->DeleteResource(id); 3595 resource_provider->DeleteResource(id);
3611 } 3596 }
3612 3597
3613 TEST_P(ResourceProviderTest, CompressedTextureETC1Upload) { 3598 TEST_P(ResourceProviderTest, CompressedTextureETC1SetPixels) {
3614 if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) 3599 if (GetParam() != ResourceProvider::GLTexture)
3615 return; 3600 return;
3616 3601
3617 scoped_ptr<AllocationTrackingContext3D> context_owned( 3602 scoped_ptr<AllocationTrackingContext3D> context_owned(
3618 new AllocationTrackingContext3D); 3603 new AllocationTrackingContext3D);
3619 AllocationTrackingContext3D* context = context_owned.get(); 3604 AllocationTrackingContext3D* context = context_owned.get();
3620 context_owned->set_support_compressed_texture_etc1(true); 3605 context_owned->set_support_compressed_texture_etc1(true);
3621 3606
3622 FakeOutputSurfaceClient output_surface_client; 3607 FakeOutputSurfaceClient output_surface_client;
3623 scoped_ptr<OutputSurface> output_surface( 3608 scoped_ptr<OutputSurface> output_surface(
3624 FakeOutputSurface::Create3d(context_owned.Pass())); 3609 FakeOutputSurface::Create3d(context_owned.Pass()));
3625 CHECK(output_surface->BindToClient(&output_surface_client)); 3610 CHECK(output_surface->BindToClient(&output_surface_client));
3626 3611
3627 gfx::Size size(4, 4); 3612 gfx::Size size(4, 4);
3628 scoped_ptr<ResourceProvider> resource_provider( 3613 scoped_ptr<ResourceProvider> resource_provider(
3629 ResourceProvider::Create(output_surface.get(), 3614 ResourceProvider::Create(output_surface.get(),
3630 shared_bitmap_manager_.get(), 3615 shared_bitmap_manager_.get(),
3631 gpu_memory_buffer_manager_.get(), 3616 gpu_memory_buffer_manager_.get(),
3632 NULL, 3617 NULL,
3633 0, 3618 0,
3634 false, 3619 false,
3635 1)); 3620 1));
3636 int texture_id = 123; 3621 int texture_id = 123;
3637 uint8_t pixels[8]; 3622 uint8_t pixels[8];
3638 3623
3639 ResourceProvider::ResourceId id = resource_provider->CreateResource( 3624 ResourceProvider::ResourceId id = resource_provider->CreateResource(
3640 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, ETC1); 3625 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, ETC1);
3641 EXPECT_NE(0u, id); 3626 EXPECT_NE(0u, id);
3642 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); 3627 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
3643 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(3); 3628 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(3);
3644 EXPECT_CALL(*context, 3629 EXPECT_CALL(*context,
3645 compressedTexImage2D( 3630 compressedTexImage2D(
3646 _, 0, _, size.width(), size.height(), _, _, _)).Times(1); 3631 _, 0, _, size.width(), size.height(), _, _, _)).Times(1);
3647 resource_provider->CopyToResource(id, pixels, size); 3632 resource_provider->SetPixels(
3633 id, pixels, gfx::Rect(size), gfx::Rect(size), gfx::Vector2d(0, 0));
3648 3634
3649 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); 3635 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1);
3650 resource_provider->DeleteResource(id); 3636 resource_provider->DeleteResource(id);
3651 } 3637 }
3652 3638
3653 INSTANTIATE_TEST_CASE_P( 3639 INSTANTIATE_TEST_CASE_P(
3654 ResourceProviderTests, 3640 ResourceProviderTests,
3655 ResourceProviderTest, 3641 ResourceProviderTest,
3656 ::testing::Values(ResourceProvider::RESOURCE_TYPE_GL_TEXTURE, 3642 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap));
3657 ResourceProvider::RESOURCE_TYPE_BITMAP));
3658 3643
3659 class TextureIdAllocationTrackingContext : public TestWebGraphicsContext3D { 3644 class TextureIdAllocationTrackingContext : public TestWebGraphicsContext3D {
3660 public: 3645 public:
3661 GLuint NextTextureId() override { 3646 GLuint NextTextureId() override {
3662 base::AutoLock lock(namespace_->lock); 3647 base::AutoLock lock(namespace_->lock);
3663 return namespace_->next_texture_id++; 3648 return namespace_->next_texture_id++;
3664 } 3649 }
3665 void RetireTextureId(GLuint) override {} 3650 void RetireTextureId(GLuint) override {}
3666 GLuint PeekTextureId() { 3651 GLuint PeekTextureId() {
3667 base::AutoLock lock(namespace_->lock); 3652 base::AutoLock lock(namespace_->lock);
(...skipping 21 matching lines...) Expand all
3689 scoped_ptr<ResourceProvider> resource_provider( 3674 scoped_ptr<ResourceProvider> resource_provider(
3690 ResourceProvider::Create(output_surface.get(), 3675 ResourceProvider::Create(output_surface.get(),
3691 shared_bitmap_manager.get(), 3676 shared_bitmap_manager.get(),
3692 NULL, 3677 NULL,
3693 NULL, 3678 NULL,
3694 0, 3679 0,
3695 false, 3680 false,
3696 kTextureAllocationChunkSize)); 3681 kTextureAllocationChunkSize));
3697 3682
3698 ResourceProvider::ResourceId id = resource_provider->CreateResource( 3683 ResourceProvider::ResourceId id = resource_provider->CreateResource(
3699 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, 3684 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3700 format);
3701 resource_provider->AllocateForTesting(id); 3685 resource_provider->AllocateForTesting(id);
3702 Mock::VerifyAndClearExpectations(context); 3686 Mock::VerifyAndClearExpectations(context);
3703 3687
3704 DCHECK_EQ(2u, context->PeekTextureId()); 3688 DCHECK_EQ(2u, context->PeekTextureId());
3705 resource_provider->DeleteResource(id); 3689 resource_provider->DeleteResource(id);
3706 } 3690 }
3707 3691
3708 { 3692 {
3709 size_t kTextureAllocationChunkSize = 8; 3693 size_t kTextureAllocationChunkSize = 8;
3710 scoped_ptr<ResourceProvider> resource_provider( 3694 scoped_ptr<ResourceProvider> resource_provider(
3711 ResourceProvider::Create(output_surface.get(), 3695 ResourceProvider::Create(output_surface.get(),
3712 shared_bitmap_manager.get(), 3696 shared_bitmap_manager.get(),
3713 NULL, 3697 NULL,
3714 NULL, 3698 NULL,
3715 0, 3699 0,
3716 false, 3700 false,
3717 kTextureAllocationChunkSize)); 3701 kTextureAllocationChunkSize));
3718 3702
3719 ResourceProvider::ResourceId id = resource_provider->CreateResource( 3703 ResourceProvider::ResourceId id = resource_provider->CreateResource(
3720 size, GL_CLAMP_TO_EDGE, ResourceProvider::TEXTURE_HINT_IMMUTABLE, 3704 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3721 format);
3722 resource_provider->AllocateForTesting(id); 3705 resource_provider->AllocateForTesting(id);
3723 Mock::VerifyAndClearExpectations(context); 3706 Mock::VerifyAndClearExpectations(context);
3724 3707
3725 DCHECK_EQ(10u, context->PeekTextureId()); 3708 DCHECK_EQ(10u, context->PeekTextureId());
3726 resource_provider->DeleteResource(id); 3709 resource_provider->DeleteResource(id);
3727 } 3710 }
3728 } 3711 }
3729 3712
3730 } // namespace 3713 } // namespace
3731 } // namespace cc 3714 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/resource_provider.cc ('k') | cc/resources/scoped_resource.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698