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

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

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