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

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

Issue 486853002: cc: Use a normal texture for background texture. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address nits in unittests Created 6 years, 4 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.h » ('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 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 ResourceProvider* resource_provider, 490 ResourceProvider* resource_provider,
491 ResourceProviderContext* context) { 491 ResourceProviderContext* context) {
492 DCHECK_EQ(expected_default_type, resource_provider->default_resource_type()); 492 DCHECK_EQ(expected_default_type, resource_provider->default_resource_type());
493 493
494 gfx::Size size(1, 1); 494 gfx::Size size(1, 1);
495 ResourceFormat format = RGBA_8888; 495 ResourceFormat format = RGBA_8888;
496 size_t pixel_size = TextureSizeBytes(size, format); 496 size_t pixel_size = TextureSizeBytes(size, format);
497 ASSERT_EQ(4U, pixel_size); 497 ASSERT_EQ(4U, pixel_size);
498 498
499 ResourceProvider::ResourceId id = resource_provider->CreateResource( 499 ResourceProvider::ResourceId id = resource_provider->CreateResource(
500 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 500 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
501 EXPECT_EQ(1, static_cast<int>(resource_provider->num_resources())); 501 EXPECT_EQ(1, static_cast<int>(resource_provider->num_resources()));
502 if (expected_default_type == ResourceProvider::GLTexture) 502 if (expected_default_type == ResourceProvider::GLTexture)
503 EXPECT_EQ(0u, context->NumTextures()); 503 EXPECT_EQ(0u, context->NumTextures());
504 504
505 uint8_t data[4] = { 1, 2, 3, 4 }; 505 uint8_t data[4] = { 1, 2, 3, 4 };
506 gfx::Rect rect(size); 506 gfx::Rect rect(size);
507 resource_provider->SetPixels(id, data, rect, rect, gfx::Vector2d()); 507 resource_provider->SetPixels(id, data, rect, rect, gfx::Vector2d());
508 if (expected_default_type == ResourceProvider::GLTexture) 508 if (expected_default_type == ResourceProvider::GLTexture)
509 EXPECT_EQ(1u, context->NumTextures()); 509 EXPECT_EQ(1u, context->NumTextures());
510 510
(...skipping 11 matching lines...) Expand all
522 CheckCreateResource(GetParam(), resource_provider_.get(), context()); 522 CheckCreateResource(GetParam(), resource_provider_.get(), context());
523 } 523 }
524 524
525 TEST_P(ResourceProviderTest, Upload) { 525 TEST_P(ResourceProviderTest, Upload) {
526 gfx::Size size(2, 2); 526 gfx::Size size(2, 2);
527 ResourceFormat format = RGBA_8888; 527 ResourceFormat format = RGBA_8888;
528 size_t pixel_size = TextureSizeBytes(size, format); 528 size_t pixel_size = TextureSizeBytes(size, format);
529 ASSERT_EQ(16U, pixel_size); 529 ASSERT_EQ(16U, pixel_size);
530 530
531 ResourceProvider::ResourceId id = resource_provider_->CreateResource( 531 ResourceProvider::ResourceId id = resource_provider_->CreateResource(
532 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 532 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
533 533
534 uint8_t image[16] = { 0 }; 534 uint8_t image[16] = { 0 };
535 gfx::Rect image_rect(size); 535 gfx::Rect image_rect(size);
536 resource_provider_->SetPixels( 536 resource_provider_->SetPixels(
537 id, image, image_rect, image_rect, gfx::Vector2d()); 537 id, image, image_rect, image_rect, gfx::Vector2d());
538 538
539 for (uint8_t i = 0; i < pixel_size; ++i) 539 for (uint8_t i = 0; i < pixel_size; ++i)
540 image[i] = i; 540 image[i] = i;
541 541
542 uint8_t result[16] = { 0 }; 542 uint8_t result[16] = { 0 };
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 591
592 TEST_P(ResourceProviderTest, TransferGLResources) { 592 TEST_P(ResourceProviderTest, TransferGLResources) {
593 if (GetParam() != ResourceProvider::GLTexture) 593 if (GetParam() != ResourceProvider::GLTexture)
594 return; 594 return;
595 gfx::Size size(1, 1); 595 gfx::Size size(1, 1);
596 ResourceFormat format = RGBA_8888; 596 ResourceFormat format = RGBA_8888;
597 size_t pixel_size = TextureSizeBytes(size, format); 597 size_t pixel_size = TextureSizeBytes(size, format);
598 ASSERT_EQ(4U, pixel_size); 598 ASSERT_EQ(4U, pixel_size);
599 599
600 ResourceProvider::ResourceId id1 = child_resource_provider_->CreateResource( 600 ResourceProvider::ResourceId id1 = child_resource_provider_->CreateResource(
601 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 601 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
602 uint8_t data1[4] = { 1, 2, 3, 4 }; 602 uint8_t data1[4] = { 1, 2, 3, 4 };
603 gfx::Rect rect(size); 603 gfx::Rect rect(size);
604 child_resource_provider_->SetPixels(id1, data1, rect, rect, gfx::Vector2d()); 604 child_resource_provider_->SetPixels(id1, data1, rect, rect, gfx::Vector2d());
605 605
606 ResourceProvider::ResourceId id2 = child_resource_provider_->CreateResource( 606 ResourceProvider::ResourceId id2 = child_resource_provider_->CreateResource(
607 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 607 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
608 uint8_t data2[4] = { 5, 5, 5, 5 }; 608 uint8_t data2[4] = { 5, 5, 5, 5 };
609 child_resource_provider_->SetPixels(id2, data2, rect, rect, gfx::Vector2d()); 609 child_resource_provider_->SetPixels(id2, data2, rect, rect, gfx::Vector2d());
610 610
611 ResourceProvider::ResourceId id3 = child_resource_provider_->CreateResource( 611 ResourceProvider::ResourceId id3 = child_resource_provider_->CreateResource(
612 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 612 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
613 child_resource_provider_->MapImageRasterBuffer(id3); 613 child_resource_provider_->MapImageRasterBuffer(id3);
614 child_resource_provider_->UnmapImageRasterBuffer(id3); 614 child_resource_provider_->UnmapImageRasterBuffer(id3);
615 615
616 GLuint external_texture_id = child_context_->createExternalTexture(); 616 GLuint external_texture_id = child_context_->createExternalTexture();
617 child_context_->bindTexture(GL_TEXTURE_EXTERNAL_OES, external_texture_id); 617 child_context_->bindTexture(GL_TEXTURE_EXTERNAL_OES, external_texture_id);
618 618
619 gpu::Mailbox external_mailbox; 619 gpu::Mailbox external_mailbox;
620 child_context_->genMailboxCHROMIUM(external_mailbox.name); 620 child_context_->genMailboxCHROMIUM(external_mailbox.name);
621 child_context_->produceTextureCHROMIUM(GL_TEXTURE_EXTERNAL_OES, 621 child_context_->produceTextureCHROMIUM(GL_TEXTURE_EXTERNAL_OES,
622 external_mailbox.name); 622 external_mailbox.name);
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 EXPECT_FALSE(returned_to_child[3].lost); 832 EXPECT_FALSE(returned_to_child[3].lost);
833 } 833 }
834 834
835 TEST_P(ResourceProviderTest, ReadLockCountStopsReturnToChildOrDelete) { 835 TEST_P(ResourceProviderTest, ReadLockCountStopsReturnToChildOrDelete) {
836 if (GetParam() != ResourceProvider::GLTexture) 836 if (GetParam() != ResourceProvider::GLTexture)
837 return; 837 return;
838 gfx::Size size(1, 1); 838 gfx::Size size(1, 1);
839 ResourceFormat format = RGBA_8888; 839 ResourceFormat format = RGBA_8888;
840 840
841 ResourceProvider::ResourceId id1 = child_resource_provider_->CreateResource( 841 ResourceProvider::ResourceId id1 = child_resource_provider_->CreateResource(
842 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 842 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
843 uint8_t data1[4] = {1, 2, 3, 4}; 843 uint8_t data1[4] = {1, 2, 3, 4};
844 gfx::Rect rect(size); 844 gfx::Rect rect(size);
845 child_resource_provider_->SetPixels(id1, data1, rect, rect, gfx::Vector2d()); 845 child_resource_provider_->SetPixels(id1, data1, rect, rect, gfx::Vector2d());
846 846
847 ReturnedResourceArray returned_to_child; 847 ReturnedResourceArray returned_to_child;
848 int child_id = 848 int child_id =
849 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); 849 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child));
850 { 850 {
851 // Transfer some resources to the parent. 851 // Transfer some resources to the parent.
852 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 852 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 TEST_P(ResourceProviderTest, TransferSoftwareResources) { 938 TEST_P(ResourceProviderTest, TransferSoftwareResources) {
939 if (GetParam() != ResourceProvider::Bitmap) 939 if (GetParam() != ResourceProvider::Bitmap)
940 return; 940 return;
941 941
942 gfx::Size size(1, 1); 942 gfx::Size size(1, 1);
943 ResourceFormat format = RGBA_8888; 943 ResourceFormat format = RGBA_8888;
944 size_t pixel_size = TextureSizeBytes(size, format); 944 size_t pixel_size = TextureSizeBytes(size, format);
945 ASSERT_EQ(4U, pixel_size); 945 ASSERT_EQ(4U, pixel_size);
946 946
947 ResourceProvider::ResourceId id1 = child_resource_provider_->CreateResource( 947 ResourceProvider::ResourceId id1 = child_resource_provider_->CreateResource(
948 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 948 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
949 uint8_t data1[4] = { 1, 2, 3, 4 }; 949 uint8_t data1[4] = { 1, 2, 3, 4 };
950 gfx::Rect rect(size); 950 gfx::Rect rect(size);
951 child_resource_provider_->SetPixels(id1, data1, rect, rect, gfx::Vector2d()); 951 child_resource_provider_->SetPixels(id1, data1, rect, rect, gfx::Vector2d());
952 952
953 ResourceProvider::ResourceId id2 = child_resource_provider_->CreateResource( 953 ResourceProvider::ResourceId id2 = child_resource_provider_->CreateResource(
954 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 954 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
955 uint8_t data2[4] = { 5, 5, 5, 5 }; 955 uint8_t data2[4] = { 5, 5, 5, 5 };
956 child_resource_provider_->SetPixels(id2, data2, rect, rect, gfx::Vector2d()); 956 child_resource_provider_->SetPixels(id2, data2, rect, rect, gfx::Vector2d());
957 957
958 ResourceProvider::ResourceId id3 = child_resource_provider_->CreateResource( 958 ResourceProvider::ResourceId id3 = child_resource_provider_->CreateResource(
959 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 959 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
960 uint8_t data3[4] = { 6, 7, 8, 9 }; 960 uint8_t data3[4] = { 6, 7, 8, 9 };
961 SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.height()); 961 SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.height());
962 SkCanvas* raster_canvas = child_resource_provider_->MapImageRasterBuffer(id3); 962 SkCanvas* raster_canvas = child_resource_provider_->MapImageRasterBuffer(id3);
963 raster_canvas->writePixels(info, data3, info.minRowBytes(), 0, 0); 963 raster_canvas->writePixels(info, data3, info.minRowBytes(), 0, 0);
964 child_resource_provider_->UnmapImageRasterBuffer(id3); 964 child_resource_provider_->UnmapImageRasterBuffer(id3);
965 965
966 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); 966 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory());
967 shared_memory->CreateAndMapAnonymous(1); 967 shared_memory->CreateAndMapAnonymous(1);
968 base::SharedMemory* shared_memory_ptr = shared_memory.get(); 968 base::SharedMemory* shared_memory_ptr = shared_memory.get();
969 ResourceProvider::ResourceId id4 = 969 ResourceProvider::ResourceId id4 =
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 scoped_ptr<ResourceProvider> child_resource_provider(ResourceProvider::Create( 1174 scoped_ptr<ResourceProvider> child_resource_provider(ResourceProvider::Create(
1175 child_output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, 1175 child_output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1,
1176 false)); 1176 false));
1177 1177
1178 gfx::Size size(1, 1); 1178 gfx::Size size(1, 1);
1179 ResourceFormat format = RGBA_8888; 1179 ResourceFormat format = RGBA_8888;
1180 size_t pixel_size = TextureSizeBytes(size, format); 1180 size_t pixel_size = TextureSizeBytes(size, format);
1181 ASSERT_EQ(4U, pixel_size); 1181 ASSERT_EQ(4U, pixel_size);
1182 1182
1183 ResourceProvider::ResourceId id1 = child_resource_provider->CreateResource( 1183 ResourceProvider::ResourceId id1 = child_resource_provider->CreateResource(
1184 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 1184 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
1185 uint8_t data1[4] = { 1, 2, 3, 4 }; 1185 uint8_t data1[4] = { 1, 2, 3, 4 };
1186 gfx::Rect rect(size); 1186 gfx::Rect rect(size);
1187 child_resource_provider->SetPixels(id1, data1, rect, rect, gfx::Vector2d()); 1187 child_resource_provider->SetPixels(id1, data1, rect, rect, gfx::Vector2d());
1188 1188
1189 ReturnedResourceArray returned_to_child; 1189 ReturnedResourceArray returned_to_child;
1190 int child_id = 1190 int child_id =
1191 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); 1191 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child));
1192 { 1192 {
1193 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 1193 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
1194 resource_ids_to_transfer.push_back(id1); 1194 resource_ids_to_transfer.push_back(id1);
(...skipping 26 matching lines...) Expand all
1221 TEST_P(ResourceProviderTest, TransferInvalidSoftware) { 1221 TEST_P(ResourceProviderTest, TransferInvalidSoftware) {
1222 if (GetParam() != ResourceProvider::Bitmap) 1222 if (GetParam() != ResourceProvider::Bitmap)
1223 return; 1223 return;
1224 1224
1225 gfx::Size size(1, 1); 1225 gfx::Size size(1, 1);
1226 ResourceFormat format = RGBA_8888; 1226 ResourceFormat format = RGBA_8888;
1227 size_t pixel_size = TextureSizeBytes(size, format); 1227 size_t pixel_size = TextureSizeBytes(size, format);
1228 ASSERT_EQ(4U, pixel_size); 1228 ASSERT_EQ(4U, pixel_size);
1229 1229
1230 ResourceProvider::ResourceId id1 = child_resource_provider_->CreateResource( 1230 ResourceProvider::ResourceId id1 = child_resource_provider_->CreateResource(
1231 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 1231 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
1232 uint8_t data1[4] = { 1, 2, 3, 4 }; 1232 uint8_t data1[4] = { 1, 2, 3, 4 };
1233 gfx::Rect rect(size); 1233 gfx::Rect rect(size);
1234 child_resource_provider_->SetPixels(id1, data1, rect, rect, gfx::Vector2d()); 1234 child_resource_provider_->SetPixels(id1, data1, rect, rect, gfx::Vector2d());
1235 1235
1236 ReturnedResourceArray returned_to_child; 1236 ReturnedResourceArray returned_to_child;
1237 int child_id = 1237 int child_id =
1238 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); 1238 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child));
1239 { 1239 {
1240 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 1240 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
1241 resource_ids_to_transfer.push_back(id1); 1241 resource_ids_to_transfer.push_back(id1);
(...skipping 27 matching lines...) Expand all
1269 EXPECT_FALSE(returned_to_child[0].lost); 1269 EXPECT_FALSE(returned_to_child[0].lost);
1270 } 1270 }
1271 1271
1272 TEST_P(ResourceProviderTest, DeleteExportedResources) { 1272 TEST_P(ResourceProviderTest, DeleteExportedResources) {
1273 gfx::Size size(1, 1); 1273 gfx::Size size(1, 1);
1274 ResourceFormat format = RGBA_8888; 1274 ResourceFormat format = RGBA_8888;
1275 size_t pixel_size = TextureSizeBytes(size, format); 1275 size_t pixel_size = TextureSizeBytes(size, format);
1276 ASSERT_EQ(4U, pixel_size); 1276 ASSERT_EQ(4U, pixel_size);
1277 1277
1278 ResourceProvider::ResourceId id1 = child_resource_provider_->CreateResource( 1278 ResourceProvider::ResourceId id1 = child_resource_provider_->CreateResource(
1279 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 1279 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
1280 uint8_t data1[4] = { 1, 2, 3, 4 }; 1280 uint8_t data1[4] = { 1, 2, 3, 4 };
1281 gfx::Rect rect(size); 1281 gfx::Rect rect(size);
1282 child_resource_provider_->SetPixels(id1, data1, rect, rect, gfx::Vector2d()); 1282 child_resource_provider_->SetPixels(id1, data1, rect, rect, gfx::Vector2d());
1283 1283
1284 ResourceProvider::ResourceId id2 = child_resource_provider_->CreateResource( 1284 ResourceProvider::ResourceId id2 = child_resource_provider_->CreateResource(
1285 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 1285 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
1286 uint8_t data2[4] = {5, 5, 5, 5}; 1286 uint8_t data2[4] = {5, 5, 5, 5};
1287 child_resource_provider_->SetPixels(id2, data2, rect, rect, gfx::Vector2d()); 1287 child_resource_provider_->SetPixels(id2, data2, rect, rect, gfx::Vector2d());
1288 1288
1289 ReturnedResourceArray returned_to_child; 1289 ReturnedResourceArray returned_to_child;
1290 int child_id = 1290 int child_id =
1291 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); 1291 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child));
1292 { 1292 {
1293 // Transfer some resources to the parent. 1293 // Transfer some resources to the parent.
1294 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 1294 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
1295 resource_ids_to_transfer.push_back(id1); 1295 resource_ids_to_transfer.push_back(id1);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1363 } 1363 }
1364 } 1364 }
1365 1365
1366 TEST_P(ResourceProviderTest, DestroyChildWithExportedResources) { 1366 TEST_P(ResourceProviderTest, DestroyChildWithExportedResources) {
1367 gfx::Size size(1, 1); 1367 gfx::Size size(1, 1);
1368 ResourceFormat format = RGBA_8888; 1368 ResourceFormat format = RGBA_8888;
1369 size_t pixel_size = TextureSizeBytes(size, format); 1369 size_t pixel_size = TextureSizeBytes(size, format);
1370 ASSERT_EQ(4U, pixel_size); 1370 ASSERT_EQ(4U, pixel_size);
1371 1371
1372 ResourceProvider::ResourceId id1 = child_resource_provider_->CreateResource( 1372 ResourceProvider::ResourceId id1 = child_resource_provider_->CreateResource(
1373 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 1373 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
1374 uint8_t data1[4] = {1, 2, 3, 4}; 1374 uint8_t data1[4] = {1, 2, 3, 4};
1375 gfx::Rect rect(size); 1375 gfx::Rect rect(size);
1376 child_resource_provider_->SetPixels(id1, data1, rect, rect, gfx::Vector2d()); 1376 child_resource_provider_->SetPixels(id1, data1, rect, rect, gfx::Vector2d());
1377 1377
1378 ResourceProvider::ResourceId id2 = child_resource_provider_->CreateResource( 1378 ResourceProvider::ResourceId id2 = child_resource_provider_->CreateResource(
1379 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 1379 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
1380 uint8_t data2[4] = {5, 5, 5, 5}; 1380 uint8_t data2[4] = {5, 5, 5, 5};
1381 child_resource_provider_->SetPixels(id2, data2, rect, rect, gfx::Vector2d()); 1381 child_resource_provider_->SetPixels(id2, data2, rect, rect, gfx::Vector2d());
1382 1382
1383 ReturnedResourceArray returned_to_child; 1383 ReturnedResourceArray returned_to_child;
1384 int child_id = 1384 int child_id =
1385 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); 1385 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child));
1386 { 1386 {
1387 // Transfer some resources to the parent. 1387 // Transfer some resources to the parent.
1388 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 1388 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
1389 resource_ids_to_transfer.push_back(id1); 1389 resource_ids_to_transfer.push_back(id1);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1474 } 1474 }
1475 } 1475 }
1476 1476
1477 TEST_P(ResourceProviderTest, DeleteTransferredResources) { 1477 TEST_P(ResourceProviderTest, DeleteTransferredResources) {
1478 gfx::Size size(1, 1); 1478 gfx::Size size(1, 1);
1479 ResourceFormat format = RGBA_8888; 1479 ResourceFormat format = RGBA_8888;
1480 size_t pixel_size = TextureSizeBytes(size, format); 1480 size_t pixel_size = TextureSizeBytes(size, format);
1481 ASSERT_EQ(4U, pixel_size); 1481 ASSERT_EQ(4U, pixel_size);
1482 1482
1483 ResourceProvider::ResourceId id = child_resource_provider_->CreateResource( 1483 ResourceProvider::ResourceId id = child_resource_provider_->CreateResource(
1484 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 1484 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
1485 uint8_t data[4] = { 1, 2, 3, 4 }; 1485 uint8_t data[4] = { 1, 2, 3, 4 };
1486 gfx::Rect rect(size); 1486 gfx::Rect rect(size);
1487 child_resource_provider_->SetPixels(id, data, rect, rect, gfx::Vector2d()); 1487 child_resource_provider_->SetPixels(id, data, rect, rect, gfx::Vector2d());
1488 1488
1489 ReturnedResourceArray returned_to_child; 1489 ReturnedResourceArray returned_to_child;
1490 int child_id = 1490 int child_id =
1491 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); 1491 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child));
1492 { 1492 {
1493 // Transfer some resource to the parent. 1493 // Transfer some resource to the parent.
1494 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 1494 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
(...skipping 29 matching lines...) Expand all
1524 EXPECT_EQ(0u, child_resource_provider_->num_resources()); 1524 EXPECT_EQ(0u, child_resource_provider_->num_resources());
1525 } 1525 }
1526 1526
1527 TEST_P(ResourceProviderTest, UnuseTransferredResources) { 1527 TEST_P(ResourceProviderTest, UnuseTransferredResources) {
1528 gfx::Size size(1, 1); 1528 gfx::Size size(1, 1);
1529 ResourceFormat format = RGBA_8888; 1529 ResourceFormat format = RGBA_8888;
1530 size_t pixel_size = TextureSizeBytes(size, format); 1530 size_t pixel_size = TextureSizeBytes(size, format);
1531 ASSERT_EQ(4U, pixel_size); 1531 ASSERT_EQ(4U, pixel_size);
1532 1532
1533 ResourceProvider::ResourceId id = child_resource_provider_->CreateResource( 1533 ResourceProvider::ResourceId id = child_resource_provider_->CreateResource(
1534 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 1534 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
1535 uint8_t data[4] = {1, 2, 3, 4}; 1535 uint8_t data[4] = {1, 2, 3, 4};
1536 gfx::Rect rect(size); 1536 gfx::Rect rect(size);
1537 child_resource_provider_->SetPixels(id, data, rect, rect, gfx::Vector2d()); 1537 child_resource_provider_->SetPixels(id, data, rect, rect, gfx::Vector2d());
1538 1538
1539 ReturnedResourceArray returned_to_child; 1539 ReturnedResourceArray returned_to_child;
1540 int child_id = 1540 int child_id =
1541 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); 1541 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child));
1542 const ResourceProvider::ResourceIdMap& map = 1542 const ResourceProvider::ResourceIdMap& map =
1543 resource_provider_->GetChildToParentMap(child_id); 1543 resource_provider_->GetChildToParentMap(child_id);
1544 { 1544 {
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1675 1675
1676 gfx::Size size(1, 1); 1676 gfx::Size size(1, 1);
1677 ResourceFormat format = RGBA_8888; 1677 ResourceFormat format = RGBA_8888;
1678 int child_texture_id = 1; 1678 int child_texture_id = 1;
1679 int parent_texture_id = 2; 1679 int parent_texture_id = 2;
1680 1680
1681 size_t pixel_size = TextureSizeBytes(size, format); 1681 size_t pixel_size = TextureSizeBytes(size, format);
1682 ASSERT_EQ(4U, pixel_size); 1682 ASSERT_EQ(4U, pixel_size);
1683 1683
1684 ResourceProvider::ResourceId id = child_resource_provider->CreateResource( 1684 ResourceProvider::ResourceId id = child_resource_provider->CreateResource(
1685 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 1685 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
1686 1686
1687 // The new texture is created with GL_LINEAR. 1687 // The new texture is created with GL_LINEAR.
1688 EXPECT_CALL(*child_context, bindTexture(GL_TEXTURE_2D, child_texture_id)) 1688 EXPECT_CALL(*child_context, bindTexture(GL_TEXTURE_2D, child_texture_id))
1689 .Times(2); // Once to create and once to allocate. 1689 .Times(2); // Once to create and once to allocate.
1690 EXPECT_CALL(*child_context, 1690 EXPECT_CALL(*child_context,
1691 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); 1691 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
1692 EXPECT_CALL(*child_context, 1692 EXPECT_CALL(*child_context,
1693 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); 1693 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
1694 EXPECT_CALL( 1694 EXPECT_CALL(
1695 *child_context, 1695 *child_context,
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1941 context()->bindTexture(GL_TEXTURE_2D, texture); 1941 context()->bindTexture(GL_TEXTURE_2D, texture);
1942 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); 1942 context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
1943 context()->deleteTexture(texture); 1943 context()->deleteTexture(texture);
1944 } 1944 }
1945 1945
1946 TEST_P(ResourceProviderTest, LostResourceInParent) { 1946 TEST_P(ResourceProviderTest, LostResourceInParent) {
1947 gfx::Size size(1, 1); 1947 gfx::Size size(1, 1);
1948 ResourceFormat format = RGBA_8888; 1948 ResourceFormat format = RGBA_8888;
1949 ResourceProvider::ResourceId resource = 1949 ResourceProvider::ResourceId resource =
1950 child_resource_provider_->CreateResource( 1950 child_resource_provider_->CreateResource(
1951 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 1951 size,
1952 GL_CLAMP_TO_EDGE,
1953 ResourceProvider::TextureHintImmutable,
1954 format);
1952 child_resource_provider_->AllocateForTesting(resource); 1955 child_resource_provider_->AllocateForTesting(resource);
1953 // Expect a GL resource to be lost. 1956 // Expect a GL resource to be lost.
1954 bool should_lose_resource = GetParam() == ResourceProvider::GLTexture; 1957 bool should_lose_resource = GetParam() == ResourceProvider::GLTexture;
1955 1958
1956 ReturnedResourceArray returned_to_child; 1959 ReturnedResourceArray returned_to_child;
1957 int child_id = 1960 int child_id =
1958 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); 1961 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child));
1959 { 1962 {
1960 // Transfer the resource to the parent. 1963 // Transfer the resource to the parent.
1961 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 1964 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1994 // Lost resources stay in use in the parent forever. 1997 // Lost resources stay in use in the parent forever.
1995 EXPECT_EQ(should_lose_resource, 1998 EXPECT_EQ(should_lose_resource,
1996 child_resource_provider_->InUseByConsumer(resource)); 1999 child_resource_provider_->InUseByConsumer(resource));
1997 } 2000 }
1998 2001
1999 TEST_P(ResourceProviderTest, LostResourceInGrandParent) { 2002 TEST_P(ResourceProviderTest, LostResourceInGrandParent) {
2000 gfx::Size size(1, 1); 2003 gfx::Size size(1, 1);
2001 ResourceFormat format = RGBA_8888; 2004 ResourceFormat format = RGBA_8888;
2002 ResourceProvider::ResourceId resource = 2005 ResourceProvider::ResourceId resource =
2003 child_resource_provider_->CreateResource( 2006 child_resource_provider_->CreateResource(
2004 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 2007 size,
2008 GL_CLAMP_TO_EDGE,
2009 ResourceProvider::TextureHintImmutable,
2010 format);
2005 child_resource_provider_->AllocateForTesting(resource); 2011 child_resource_provider_->AllocateForTesting(resource);
2006 2012
2007 ReturnedResourceArray returned_to_child; 2013 ReturnedResourceArray returned_to_child;
2008 int child_id = 2014 int child_id =
2009 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); 2015 resource_provider_->CreateChild(GetReturnCallback(&returned_to_child));
2010 { 2016 {
2011 // Transfer the resource to the parent. 2017 // Transfer the resource to the parent.
2012 ResourceProvider::ResourceIdArray resource_ids_to_transfer; 2018 ResourceProvider::ResourceIdArray resource_ids_to_transfer;
2013 resource_ids_to_transfer.push_back(resource); 2019 resource_ids_to_transfer.push_back(resource);
2014 TransferableResourceArray list; 2020 TransferableResourceArray list;
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
2280 CHECK(output_surface->BindToClient(&output_surface_client)); 2286 CHECK(output_surface->BindToClient(&output_surface_client));
2281 2287
2282 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( 2288 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
2283 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false)); 2289 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false));
2284 2290
2285 gfx::Size size(1, 1); 2291 gfx::Size size(1, 1);
2286 ResourceFormat format = RGBA_8888; 2292 ResourceFormat format = RGBA_8888;
2287 int texture_id = 1; 2293 int texture_id = 1;
2288 2294
2289 ResourceProvider::ResourceId id = resource_provider->CreateResource( 2295 ResourceProvider::ResourceId id = resource_provider->CreateResource(
2290 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 2296 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
2291 2297
2292 // Check that the texture gets created with the right sampler settings. 2298 // Check that the texture gets created with the right sampler settings.
2293 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)) 2299 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id))
2294 .Times(2); // Once to create and once to allocate. 2300 .Times(2); // Once to create and once to allocate.
2295 EXPECT_CALL(*context, 2301 EXPECT_CALL(*context,
2296 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); 2302 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
2297 EXPECT_CALL(*context, 2303 EXPECT_CALL(*context,
2298 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); 2304 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
2299 EXPECT_CALL( 2305 EXPECT_CALL(
2300 *context, 2306 *context,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
2365 2371
2366 gfx::Size size(1, 1); 2372 gfx::Size size(1, 1);
2367 ResourceFormat format = RGBA_8888; 2373 ResourceFormat format = RGBA_8888;
2368 int texture_id = 1; 2374 int texture_id = 1;
2369 2375
2370 // Check that the texture gets created with the right sampler settings. 2376 // Check that the texture gets created with the right sampler settings.
2371 ResourceProvider::ResourceId id = resource_provider->CreateManagedResource( 2377 ResourceProvider::ResourceId id = resource_provider->CreateManagedResource(
2372 size, 2378 size,
2373 GL_TEXTURE_2D, 2379 GL_TEXTURE_2D,
2374 GL_CLAMP_TO_EDGE, 2380 GL_CLAMP_TO_EDGE,
2375 ResourceProvider::TextureUsageAny, 2381 ResourceProvider::TextureHintImmutable,
2376 format); 2382 format);
2377 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)); 2383 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id));
2378 EXPECT_CALL(*context, 2384 EXPECT_CALL(*context,
2379 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); 2385 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
2380 EXPECT_CALL(*context, 2386 EXPECT_CALL(*context,
2381 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); 2387 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
2382 EXPECT_CALL( 2388 EXPECT_CALL(
2383 *context, 2389 *context,
2384 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); 2390 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
2385 EXPECT_CALL( 2391 EXPECT_CALL(
(...skipping 26 matching lines...) Expand all
2412 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( 2418 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
2413 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false)); 2419 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false));
2414 2420
2415 gfx::Size size(1, 1); 2421 gfx::Size size(1, 1);
2416 ResourceFormat format = RGBA_8888; 2422 ResourceFormat format = RGBA_8888;
2417 GLenum texture_pool = GL_TEXTURE_POOL_UNMANAGED_CHROMIUM; 2423 GLenum texture_pool = GL_TEXTURE_POOL_UNMANAGED_CHROMIUM;
2418 2424
2419 for (int texture_id = 1; texture_id <= 2; ++texture_id) { 2425 for (int texture_id = 1; texture_id <= 2; ++texture_id) {
2420 GLint wrap_mode = texture_id == 1 ? GL_CLAMP_TO_EDGE : GL_REPEAT; 2426 GLint wrap_mode = texture_id == 1 ? GL_CLAMP_TO_EDGE : GL_REPEAT;
2421 // Check that the texture gets created with the right sampler settings. 2427 // Check that the texture gets created with the right sampler settings.
2428 ResourceProvider::ResourceId id = resource_provider->CreateGLTexture(
2429 size,
2430 GL_TEXTURE_2D,
2431 texture_pool,
2432 wrap_mode,
2433 ResourceProvider::TextureHintImmutable,
2434 format);
2435 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id));
2436 EXPECT_CALL(*context,
2437 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
2438 EXPECT_CALL(*context,
2439 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
2440 EXPECT_CALL(*context,
2441 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_mode));
2442 EXPECT_CALL(*context,
2443 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_mode));
2444 EXPECT_CALL(*context,
2445 texParameteri(GL_TEXTURE_2D,
2446 GL_TEXTURE_POOL_CHROMIUM,
2447 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM));
2448 resource_provider->CreateForTesting(id);
2449 EXPECT_NE(0u, id);
2450
2451 Mock::VerifyAndClearExpectations(context);
2452 }
2453 }
2454
2455 TEST_P(ResourceProviderTest, TextureHint) {
2456 // Sampling is only supported for GL textures.
2457 if (GetParam() != ResourceProvider::GLTexture)
2458 return;
2459
2460 scoped_ptr<TextureStateTrackingContext> context_owned(
2461 new TextureStateTrackingContext);
2462 TextureStateTrackingContext* context = context_owned.get();
2463 context->set_support_texture_storage(true);
2464 context->set_support_texture_usage(true);
2465
2466 FakeOutputSurfaceClient output_surface_client;
2467 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
2468 context_owned.PassAs<TestWebGraphicsContext3D>()));
2469 CHECK(output_surface->BindToClient(&output_surface_client));
2470
2471 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
2472 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false));
2473
2474 gfx::Size size(1, 1);
2475 ResourceFormat format = RGBA_8888;
2476 GLenum texture_pool = GL_TEXTURE_POOL_UNMANAGED_CHROMIUM;
2477
2478 const ResourceProvider::TextureHint hints[4] = {
2479 ResourceProvider::TextureHintDefault,
2480 ResourceProvider::TextureHintImmutable,
2481 ResourceProvider::TextureHintFramebuffer,
2482 ResourceProvider::TextureHintImmutableFramebuffer,
2483 };
2484 for (GLuint texture_id = 1; texture_id <= arraysize(hints); ++texture_id) {
2485 // Check that the texture gets created with the right sampler settings.
2422 ResourceProvider::ResourceId id = 2486 ResourceProvider::ResourceId id =
2423 resource_provider->CreateGLTexture(size, 2487 resource_provider->CreateGLTexture(size,
2424 GL_TEXTURE_2D, 2488 GL_TEXTURE_2D,
2425 texture_pool, 2489 texture_pool,
2426 wrap_mode, 2490 GL_CLAMP_TO_EDGE,
2427 ResourceProvider::TextureUsageAny, 2491 hints[texture_id - 1],
2428 format); 2492 format);
2429 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)); 2493 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id));
2430 EXPECT_CALL(*context, 2494 EXPECT_CALL(*context,
2431 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); 2495 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
2432 EXPECT_CALL(*context, 2496 EXPECT_CALL(*context,
2433 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); 2497 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
2434 EXPECT_CALL( 2498 EXPECT_CALL(
2435 *context, 2499 *context,
2436 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_mode)); 2500 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
2437 EXPECT_CALL( 2501 EXPECT_CALL(
2438 *context, 2502 *context,
2439 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_mode)); 2503 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
2440 EXPECT_CALL(*context, 2504 EXPECT_CALL(*context,
2441 texParameteri(GL_TEXTURE_2D, 2505 texParameteri(GL_TEXTURE_2D,
2442 GL_TEXTURE_POOL_CHROMIUM, 2506 GL_TEXTURE_POOL_CHROMIUM,
2443 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM)); 2507 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM));
2508 // Check only TextureHintFramebuffer set GL_TEXTURE_USAGE_ANGLE.
2509 bool is_framebuffer_hint =
2510 hints[texture_id - 1] & ResourceProvider::TextureHintFramebuffer;
2511 EXPECT_CALL(*context,
2512 texParameteri(GL_TEXTURE_2D,
2513 GL_TEXTURE_USAGE_ANGLE,
2514 GL_FRAMEBUFFER_ATTACHMENT_ANGLE))
2515 .Times(is_framebuffer_hint ? 1 : 0);
2444 resource_provider->CreateForTesting(id); 2516 resource_provider->CreateForTesting(id);
2445 EXPECT_NE(0u, id); 2517 EXPECT_NE(0u, id);
2446 2518
2447 Mock::VerifyAndClearExpectations(context); 2519 Mock::VerifyAndClearExpectations(context);
2448 } 2520 }
2449 } 2521 }
2450 2522
2451 TEST_P(ResourceProviderTest, TextureMailbox_SharedMemory) { 2523 TEST_P(ResourceProviderTest, TextureMailbox_SharedMemory) {
2452 if (GetParam() != ResourceProvider::Bitmap) 2524 if (GetParam() != ResourceProvider::Bitmap)
2453 return; 2525 return;
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
2816 gfx::Size size(2, 2); 2888 gfx::Size size(2, 2);
2817 gfx::Vector2d offset(0, 0); 2889 gfx::Vector2d offset(0, 0);
2818 gfx::Rect rect(0, 0, 2, 2); 2890 gfx::Rect rect(0, 0, 2, 2);
2819 ResourceFormat format = RGBA_8888; 2891 ResourceFormat format = RGBA_8888;
2820 ResourceProvider::ResourceId id = 0; 2892 ResourceProvider::ResourceId id = 0;
2821 uint8_t pixels[16] = { 0 }; 2893 uint8_t pixels[16] = { 0 };
2822 int texture_id = 123; 2894 int texture_id = 123;
2823 2895
2824 // Lazy allocation. Don't allocate when creating the resource. 2896 // Lazy allocation. Don't allocate when creating the resource.
2825 id = resource_provider->CreateResource( 2897 id = resource_provider->CreateResource(
2826 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 2898 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
2827 2899
2828 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); 2900 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
2829 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1); 2901 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1);
2830 resource_provider->CreateForTesting(id); 2902 resource_provider->CreateForTesting(id);
2831 2903
2832 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); 2904 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1);
2833 resource_provider->DeleteResource(id); 2905 resource_provider->DeleteResource(id);
2834 2906
2835 Mock::VerifyAndClearExpectations(context); 2907 Mock::VerifyAndClearExpectations(context);
2836 2908
2837 // Do allocate when we set the pixels. 2909 // Do allocate when we set the pixels.
2838 id = resource_provider->CreateResource( 2910 id = resource_provider->CreateResource(
2839 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 2911 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
2840 2912
2841 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); 2913 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
2842 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(3); 2914 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(3);
2843 EXPECT_CALL(*context, texImage2D(_, _, _, 2, 2, _, _, _, _)).Times(1); 2915 EXPECT_CALL(*context, texImage2D(_, _, _, 2, 2, _, _, _, _)).Times(1);
2844 EXPECT_CALL(*context, texSubImage2D(_, _, _, _, 2, 2, _, _, _)).Times(1); 2916 EXPECT_CALL(*context, texSubImage2D(_, _, _, _, 2, 2, _, _, _)).Times(1);
2845 resource_provider->SetPixels(id, pixels, rect, rect, offset); 2917 resource_provider->SetPixels(id, pixels, rect, rect, offset);
2846 2918
2847 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); 2919 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1);
2848 resource_provider->DeleteResource(id); 2920 resource_provider->DeleteResource(id);
2849 2921
2850 Mock::VerifyAndClearExpectations(context); 2922 Mock::VerifyAndClearExpectations(context);
2851 2923
2852 // Same for async version. 2924 // Same for async version.
2853 id = resource_provider->CreateResource( 2925 id = resource_provider->CreateResource(
2854 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 2926 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
2855 resource_provider->AcquirePixelRasterBuffer(id); 2927 resource_provider->AcquirePixelRasterBuffer(id);
2856 2928
2857 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); 2929 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
2858 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); 2930 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2);
2859 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) 2931 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _))
2860 .Times(1); 2932 .Times(1);
2861 resource_provider->BeginSetPixels(id); 2933 resource_provider->BeginSetPixels(id);
2862 ASSERT_TRUE(resource_provider->DidSetPixelsComplete(id)); 2934 ASSERT_TRUE(resource_provider->DidSetPixelsComplete(id));
2863 2935
2864 resource_provider->ReleasePixelRasterBuffer(id); 2936 resource_provider->ReleasePixelRasterBuffer(id);
2865 2937
2866 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); 2938 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1);
2867 resource_provider->DeleteResource(id); 2939 resource_provider->DeleteResource(id);
2868 2940
2869 Mock::VerifyAndClearExpectations(context); 2941 Mock::VerifyAndClearExpectations(context);
2870 } 2942 }
2871 2943
2872 TEST_P(ResourceProviderTest, TextureAllocationStorageUsageAny) { 2944 TEST_P(ResourceProviderTest, TextureAllocationHint) {
2873 // Only for GL textures. 2945 // Only for GL textures.
2874 if (GetParam() != ResourceProvider::GLTexture) 2946 if (GetParam() != ResourceProvider::GLTexture)
2875 return; 2947 return;
2876 scoped_ptr<AllocationTrackingContext3D> context_owned(
2877 new StrictMock<AllocationTrackingContext3D>);
2878 AllocationTrackingContext3D* context = context_owned.get();
2879 context->set_support_texture_storage(true);
2880
2881 FakeOutputSurfaceClient output_surface_client;
2882 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
2883 context_owned.PassAs<TestWebGraphicsContext3D>()));
2884 CHECK(output_surface->BindToClient(&output_surface_client));
2885
2886 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
2887 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false));
2888
2889 gfx::Size size(2, 2);
2890 ResourceFormat format = RGBA_8888;
2891 ResourceProvider::ResourceId id = 0;
2892 int texture_id = 123;
2893
2894 // Lazy allocation. Don't allocate when creating the resource.
2895 id = resource_provider->CreateResource(
2896 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
2897
2898 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
2899 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2);
2900 EXPECT_CALL(*context, texStorage2DEXT(_, _, _, 2, 2)).Times(1);
2901 resource_provider->AllocateForTesting(id);
2902
2903 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1);
2904 resource_provider->DeleteResource(id);
2905
2906 Mock::VerifyAndClearExpectations(context);
2907 }
2908
2909 TEST_P(ResourceProviderTest, TextureAllocationStorageUsageFramebuffer) {
2910 // Only for GL textures.
2911 if (GetParam() != ResourceProvider::GLTexture)
2912 return;
2913 scoped_ptr<AllocationTrackingContext3D> context_owned( 2948 scoped_ptr<AllocationTrackingContext3D> context_owned(
2914 new StrictMock<AllocationTrackingContext3D>); 2949 new StrictMock<AllocationTrackingContext3D>);
2915 AllocationTrackingContext3D* context = context_owned.get(); 2950 AllocationTrackingContext3D* context = context_owned.get();
2916 context->set_support_texture_storage(true); 2951 context->set_support_texture_storage(true);
2952 context->set_support_texture_usage(true);
2917 2953
2918 FakeOutputSurfaceClient output_surface_client; 2954 FakeOutputSurfaceClient output_surface_client;
2919 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( 2955 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
2920 context_owned.PassAs<TestWebGraphicsContext3D>())); 2956 context_owned.PassAs<TestWebGraphicsContext3D>()));
2921 CHECK(output_surface->BindToClient(&output_surface_client)); 2957 CHECK(output_surface->BindToClient(&output_surface_client));
2922 2958
2923 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( 2959 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
2924 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false)); 2960 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false));
2925 2961
2926 gfx::Size size(2, 2); 2962 gfx::Size size(2, 2);
2927 ResourceFormat format = RGBA_8888; 2963 ResourceFormat format = RGBA_8888;
2928 ResourceProvider::ResourceId id = 0;
2929 int texture_id = 123;
2930 2964
2931 // Lazy allocation. Don't allocate when creating the resource. 2965 const ResourceProvider::TextureHint hints[4] = {
2932 id = resource_provider->CreateResource( 2966 ResourceProvider::TextureHintDefault,
2933 size, 2967 ResourceProvider::TextureHintImmutable,
2934 GL_CLAMP_TO_EDGE, 2968 ResourceProvider::TextureHintFramebuffer,
2935 ResourceProvider::TextureUsageFramebuffer, 2969 ResourceProvider::TextureHintImmutableFramebuffer,
2936 format); 2970 };
2971 for (GLuint texture_id = 1; texture_id <= arraysize(hints); ++texture_id) {
2972 // Lazy allocation. Don't allocate when creating the resource.
2973 ResourceProvider::ResourceId id = resource_provider->CreateResource(
2974 size, GL_CLAMP_TO_EDGE, hints[texture_id - 1], format);
2937 2975
2938 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); 2976 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
2939 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); 2977 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2);
2940 EXPECT_CALL(*context, texImage2D(_, _, _, 2, 2, _, _, _, _)).Times(1); 2978 bool is_immutable_hint =
2941 resource_provider->AllocateForTesting(id); 2979 hints[texture_id - 1] & ResourceProvider::TextureHintImmutable;
2980 EXPECT_CALL(*context, texStorage2DEXT(_, _, _, 2, 2))
2981 .Times(is_immutable_hint ? 1 : 0);
2982 EXPECT_CALL(*context, texImage2D(_, _, _, 2, 2, _, _, _, _))
2983 .Times(is_immutable_hint ? 0 : 1);
2984 resource_provider->AllocateForTesting(id);
2942 2985
2943 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); 2986 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1);
2944 resource_provider->DeleteResource(id); 2987 resource_provider->DeleteResource(id);
2945 2988
2946 Mock::VerifyAndClearExpectations(context); 2989 Mock::VerifyAndClearExpectations(context);
2990 }
2947 } 2991 }
2948 2992
2949 TEST_P(ResourceProviderTest, PixelBuffer_GLTexture) { 2993 TEST_P(ResourceProviderTest, PixelBuffer_GLTexture) {
2950 if (GetParam() != ResourceProvider::GLTexture) 2994 if (GetParam() != ResourceProvider::GLTexture)
2951 return; 2995 return;
2952 scoped_ptr<AllocationTrackingContext3D> context_owned( 2996 scoped_ptr<AllocationTrackingContext3D> context_owned(
2953 new StrictMock<AllocationTrackingContext3D>); 2997 new StrictMock<AllocationTrackingContext3D>);
2954 AllocationTrackingContext3D* context = context_owned.get(); 2998 AllocationTrackingContext3D* context = context_owned.get();
2955 2999
2956 FakeOutputSurfaceClient output_surface_client; 3000 FakeOutputSurfaceClient output_surface_client;
2957 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( 3001 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
2958 context_owned.PassAs<TestWebGraphicsContext3D>())); 3002 context_owned.PassAs<TestWebGraphicsContext3D>()));
2959 CHECK(output_surface->BindToClient(&output_surface_client)); 3003 CHECK(output_surface->BindToClient(&output_surface_client));
2960 3004
2961 gfx::Size size(2, 2); 3005 gfx::Size size(2, 2);
2962 ResourceFormat format = RGBA_8888; 3006 ResourceFormat format = RGBA_8888;
2963 ResourceProvider::ResourceId id = 0; 3007 ResourceProvider::ResourceId id = 0;
2964 int texture_id = 123; 3008 int texture_id = 123;
2965 3009
2966 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( 3010 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
2967 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false)); 3011 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false));
2968 3012
2969 id = resource_provider->CreateResource( 3013 id = resource_provider->CreateResource(
2970 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 3014 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
2971 resource_provider->AcquirePixelRasterBuffer(id); 3015 resource_provider->AcquirePixelRasterBuffer(id);
2972 3016
2973 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); 3017 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
2974 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); 3018 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2);
2975 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) 3019 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _))
2976 .Times(1); 3020 .Times(1);
2977 resource_provider->BeginSetPixels(id); 3021 resource_provider->BeginSetPixels(id);
2978 3022
2979 EXPECT_TRUE(resource_provider->DidSetPixelsComplete(id)); 3023 EXPECT_TRUE(resource_provider->DidSetPixelsComplete(id));
2980 3024
(...skipping 20 matching lines...) Expand all
3001 3045
3002 gfx::Size size(2, 2); 3046 gfx::Size size(2, 2);
3003 ResourceFormat format = RGBA_8888; 3047 ResourceFormat format = RGBA_8888;
3004 ResourceProvider::ResourceId id = 0; 3048 ResourceProvider::ResourceId id = 0;
3005 int texture_id = 123; 3049 int texture_id = 123;
3006 3050
3007 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( 3051 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
3008 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false)); 3052 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false));
3009 3053
3010 id = resource_provider->CreateResource( 3054 id = resource_provider->CreateResource(
3011 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 3055 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3012 resource_provider->AcquirePixelRasterBuffer(id); 3056 resource_provider->AcquirePixelRasterBuffer(id);
3013 3057
3014 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); 3058 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
3015 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); 3059 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2);
3016 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) 3060 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _))
3017 .Times(1); 3061 .Times(1);
3018 resource_provider->BeginSetPixels(id); 3062 resource_provider->BeginSetPixels(id);
3019 3063
3020 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1); 3064 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1);
3021 EXPECT_CALL(*context, waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)).Times(1); 3065 EXPECT_CALL(*context, waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)).Times(1);
(...skipping 22 matching lines...) Expand all
3044 ResourceFormat format = RGBA_8888; 3088 ResourceFormat format = RGBA_8888;
3045 ResourceProvider::ResourceId id = 0; 3089 ResourceProvider::ResourceId id = 0;
3046 int texture_id = 123; 3090 int texture_id = 123;
3047 3091
3048 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( 3092 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
3049 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false)); 3093 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false));
3050 3094
3051 EXPECT_CALL(*context, NextTextureId()).WillRepeatedly(Return(texture_id)); 3095 EXPECT_CALL(*context, NextTextureId()).WillRepeatedly(Return(texture_id));
3052 3096
3053 id = resource_provider->CreateResource( 3097 id = resource_provider->CreateResource(
3054 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 3098 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3055 context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, 3099 context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
3056 GL_INNOCENT_CONTEXT_RESET_ARB); 3100 GL_INNOCENT_CONTEXT_RESET_ARB);
3057 3101
3058 resource_provider->AcquirePixelRasterBuffer(id); 3102 resource_provider->AcquirePixelRasterBuffer(id);
3059 SkCanvas* raster_canvas = resource_provider->MapPixelRasterBuffer(id); 3103 SkCanvas* raster_canvas = resource_provider->MapPixelRasterBuffer(id);
3060 EXPECT_TRUE(raster_canvas == NULL); 3104 EXPECT_TRUE(raster_canvas == NULL);
3061 resource_provider->UnmapPixelRasterBuffer(id); 3105 resource_provider->UnmapPixelRasterBuffer(id);
3062 resource_provider->ReleasePixelRasterBuffer(id); 3106 resource_provider->ReleasePixelRasterBuffer(id);
3063 Mock::VerifyAndClearExpectations(context); 3107 Mock::VerifyAndClearExpectations(context);
3064 } 3108 }
(...skipping 16 matching lines...) Expand all
3081 gfx::Size size(kWidth, kHeight); 3125 gfx::Size size(kWidth, kHeight);
3082 ResourceFormat format = RGBA_8888; 3126 ResourceFormat format = RGBA_8888;
3083 ResourceProvider::ResourceId id = 0; 3127 ResourceProvider::ResourceId id = 0;
3084 const unsigned kTextureId = 123u; 3128 const unsigned kTextureId = 123u;
3085 const unsigned kImageId = 234u; 3129 const unsigned kImageId = 234u;
3086 3130
3087 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( 3131 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
3088 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false)); 3132 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false));
3089 3133
3090 id = resource_provider->CreateResource( 3134 id = resource_provider->CreateResource(
3091 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 3135 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3092 3136
3093 const int kStride = 4; 3137 const int kStride = 4;
3094 void* dummy_mapped_buffer_address = NULL; 3138 void* dummy_mapped_buffer_address = NULL;
3095 EXPECT_CALL( 3139 EXPECT_CALL(
3096 *context, 3140 *context,
3097 createImageCHROMIUM(kWidth, kHeight, GL_RGBA8_OES, GL_IMAGE_MAP_CHROMIUM)) 3141 createImageCHROMIUM(kWidth, kHeight, GL_RGBA8_OES, GL_IMAGE_MAP_CHROMIUM))
3098 .WillOnce(Return(kImageId)) 3142 .WillOnce(Return(kImageId))
3099 .RetiresOnSaturation(); 3143 .RetiresOnSaturation();
3100 EXPECT_CALL(*context, getImageParameterivCHROMIUM(kImageId, 3144 EXPECT_CALL(*context, getImageParameterivCHROMIUM(kImageId,
3101 GL_IMAGE_ROWBYTES_CHROMIUM, 3145 GL_IMAGE_ROWBYTES_CHROMIUM,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
3175 3219
3176 gfx::Size size(1, 1); 3220 gfx::Size size(1, 1);
3177 ResourceFormat format = RGBA_8888; 3221 ResourceFormat format = RGBA_8888;
3178 ResourceProvider::ResourceId id = 0; 3222 ResourceProvider::ResourceId id = 0;
3179 const uint32_t kBadBeef = 0xbadbeef; 3223 const uint32_t kBadBeef = 0xbadbeef;
3180 3224
3181 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( 3225 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
3182 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false)); 3226 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false));
3183 3227
3184 id = resource_provider->CreateResource( 3228 id = resource_provider->CreateResource(
3185 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 3229 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3186 3230
3187 SkBitmap bitmap; 3231 SkBitmap bitmap;
3188 bitmap.allocN32Pixels(size.width(), size.height()); 3232 bitmap.allocN32Pixels(size.width(), size.height());
3189 *(bitmap.getAddr32(0, 0)) = kBadBeef; 3233 *(bitmap.getAddr32(0, 0)) = kBadBeef;
3190 SkCanvas* canvas = resource_provider->MapImageRasterBuffer(id); 3234 SkCanvas* canvas = resource_provider->MapImageRasterBuffer(id);
3191 ASSERT_TRUE(!!canvas); 3235 ASSERT_TRUE(!!canvas);
3192 canvas->writePixels(bitmap, 0, 0); 3236 canvas->writePixels(bitmap, 0, 0);
3193 resource_provider->UnmapImageRasterBuffer(id); 3237 resource_provider->UnmapImageRasterBuffer(id);
3194 3238
3195 { 3239 {
(...skipping 27 matching lines...) Expand all
3223 ResourceProvider::ResourceId source_id = 0; 3267 ResourceProvider::ResourceId source_id = 0;
3224 ResourceProvider::ResourceId dest_id = 0; 3268 ResourceProvider::ResourceId dest_id = 0;
3225 const unsigned kSourceTextureId = 123u; 3269 const unsigned kSourceTextureId = 123u;
3226 const unsigned kDestTextureId = 321u; 3270 const unsigned kDestTextureId = 321u;
3227 const unsigned kImageId = 234u; 3271 const unsigned kImageId = 234u;
3228 3272
3229 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( 3273 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
3230 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false)); 3274 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false));
3231 3275
3232 source_id = resource_provider->CreateResource( 3276 source_id = resource_provider->CreateResource(
3233 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 3277 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3234 3278
3235 const int kStride = 4; 3279 const int kStride = 4;
3236 void* dummy_mapped_buffer_address = NULL; 3280 void* dummy_mapped_buffer_address = NULL;
3237 EXPECT_CALL( 3281 EXPECT_CALL(
3238 *context, 3282 *context,
3239 createImageCHROMIUM(kWidth, kHeight, GL_RGBA8_OES, GL_IMAGE_MAP_CHROMIUM)) 3283 createImageCHROMIUM(kWidth, kHeight, GL_RGBA8_OES, GL_IMAGE_MAP_CHROMIUM))
3240 .WillOnce(Return(kImageId)) 3284 .WillOnce(Return(kImageId))
3241 .RetiresOnSaturation(); 3285 .RetiresOnSaturation();
3242 EXPECT_CALL( 3286 EXPECT_CALL(
3243 *context, 3287 *context,
3244 getImageParameterivCHROMIUM(kImageId, GL_IMAGE_ROWBYTES_CHROMIUM, _)) 3288 getImageParameterivCHROMIUM(kImageId, GL_IMAGE_ROWBYTES_CHROMIUM, _))
3245 .WillOnce(SetArgPointee<2>(kStride)) 3289 .WillOnce(SetArgPointee<2>(kStride))
3246 .RetiresOnSaturation(); 3290 .RetiresOnSaturation();
3247 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId)) 3291 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId))
3248 .WillOnce(Return(dummy_mapped_buffer_address)) 3292 .WillOnce(Return(dummy_mapped_buffer_address))
3249 .RetiresOnSaturation(); 3293 .RetiresOnSaturation();
3250 resource_provider->MapImageRasterBuffer(source_id); 3294 resource_provider->MapImageRasterBuffer(source_id);
3251 Mock::VerifyAndClearExpectations(context); 3295 Mock::VerifyAndClearExpectations(context);
3252 3296
3253 EXPECT_CALL(*context, unmapImageCHROMIUM(kImageId)) 3297 EXPECT_CALL(*context, unmapImageCHROMIUM(kImageId))
3254 .Times(1) 3298 .Times(1)
3255 .RetiresOnSaturation(); 3299 .RetiresOnSaturation();
3256 resource_provider->UnmapImageRasterBuffer(source_id); 3300 resource_provider->UnmapImageRasterBuffer(source_id);
3257 Mock::VerifyAndClearExpectations(context); 3301 Mock::VerifyAndClearExpectations(context);
3258 3302
3259 dest_id = resource_provider->CreateResource( 3303 dest_id = resource_provider->CreateResource(
3260 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 3304 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3261 3305
3262 EXPECT_CALL(*context, NextTextureId()) 3306 EXPECT_CALL(*context, NextTextureId())
3263 .WillOnce(Return(kDestTextureId)) 3307 .WillOnce(Return(kDestTextureId))
3264 .RetiresOnSaturation(); 3308 .RetiresOnSaturation();
3265 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kDestTextureId)) 3309 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kDestTextureId))
3266 .Times(1) 3310 .Times(1)
3267 .RetiresOnSaturation(); 3311 .RetiresOnSaturation();
3268 EXPECT_CALL(*context, NextTextureId()) 3312 EXPECT_CALL(*context, NextTextureId())
3269 .WillOnce(Return(kSourceTextureId)) 3313 .WillOnce(Return(kSourceTextureId))
3270 .RetiresOnSaturation(); 3314 .RetiresOnSaturation();
(...skipping 30 matching lines...) Expand all
3301 gfx::Size size(1, 1); 3345 gfx::Size size(1, 1);
3302 ResourceFormat format = RGBA_8888; 3346 ResourceFormat format = RGBA_8888;
3303 ResourceProvider::ResourceId source_id = 0; 3347 ResourceProvider::ResourceId source_id = 0;
3304 ResourceProvider::ResourceId dest_id = 0; 3348 ResourceProvider::ResourceId dest_id = 0;
3305 const uint32_t kBadBeef = 0xbadbeef; 3349 const uint32_t kBadBeef = 0xbadbeef;
3306 3350
3307 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( 3351 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
3308 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false)); 3352 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false));
3309 3353
3310 source_id = resource_provider->CreateResource( 3354 source_id = resource_provider->CreateResource(
3311 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 3355 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3312 3356
3313 SkBitmap bitmap; 3357 SkBitmap bitmap;
3314 bitmap.allocN32Pixels(size.width(), size.height()); 3358 bitmap.allocN32Pixels(size.width(), size.height());
3315 *(bitmap.getAddr32(0, 0)) = kBadBeef; 3359 *(bitmap.getAddr32(0, 0)) = kBadBeef;
3316 SkCanvas* canvas = resource_provider->MapImageRasterBuffer(source_id); 3360 SkCanvas* canvas = resource_provider->MapImageRasterBuffer(source_id);
3317 ASSERT_TRUE(!!canvas); 3361 ASSERT_TRUE(!!canvas);
3318 canvas->writePixels(bitmap, 0, 0); 3362 canvas->writePixels(bitmap, 0, 0);
3319 resource_provider->UnmapImageRasterBuffer(source_id); 3363 resource_provider->UnmapImageRasterBuffer(source_id);
3320 3364
3321 dest_id = resource_provider->CreateResource( 3365 dest_id = resource_provider->CreateResource(
3322 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 3366 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3323 3367
3324 resource_provider->CopyResource(source_id, dest_id); 3368 resource_provider->CopyResource(source_id, dest_id);
3325 3369
3326 { 3370 {
3327 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(), 3371 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(),
3328 dest_id); 3372 dest_id);
3329 const SkBitmap* sk_bitmap = lock.sk_bitmap(); 3373 const SkBitmap* sk_bitmap = lock.sk_bitmap();
3330 EXPECT_EQ(sk_bitmap->width(), size.width()); 3374 EXPECT_EQ(sk_bitmap->width(), size.width());
3331 EXPECT_EQ(sk_bitmap->height(), size.height()); 3375 EXPECT_EQ(sk_bitmap->height(), size.height());
3332 EXPECT_EQ(*sk_bitmap->getAddr32(0, 0), kBadBeef); 3376 EXPECT_EQ(*sk_bitmap->getAddr32(0, 0), kBadBeef);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
3399 scoped_ptr<ResourceProvider> resource_provider( 3443 scoped_ptr<ResourceProvider> resource_provider(
3400 ResourceProvider::Create(output_surface.get(), 3444 ResourceProvider::Create(output_surface.get(),
3401 shared_bitmap_manager_.get(), 3445 shared_bitmap_manager_.get(),
3402 0, 3446 0,
3403 false, 3447 false,
3404 1, 3448 1,
3405 false)); 3449 false));
3406 int texture_id = 123; 3450 int texture_id = 123;
3407 3451
3408 ResourceProvider::ResourceId id = resource_provider->CreateResource( 3452 ResourceProvider::ResourceId id = resource_provider->CreateResource(
3409 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, ETC1); 3453 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, ETC1);
3410 EXPECT_NE(0u, id); 3454 EXPECT_NE(0u, id);
3411 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); 3455 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
3412 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); 3456 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2);
3413 resource_provider->AllocateForTesting(id); 3457 resource_provider->AllocateForTesting(id);
3414 3458
3415 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); 3459 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1);
3416 resource_provider->DeleteResource(id); 3460 resource_provider->DeleteResource(id);
3417 } 3461 }
3418 3462
3419 TEST_P(ResourceProviderTest, CompressedTextureETC1SetPixels) { 3463 TEST_P(ResourceProviderTest, CompressedTextureETC1SetPixels) {
(...skipping 15 matching lines...) Expand all
3435 ResourceProvider::Create(output_surface.get(), 3479 ResourceProvider::Create(output_surface.get(),
3436 shared_bitmap_manager_.get(), 3480 shared_bitmap_manager_.get(),
3437 0, 3481 0,
3438 false, 3482 false,
3439 1, 3483 1,
3440 false)); 3484 false));
3441 int texture_id = 123; 3485 int texture_id = 123;
3442 uint8_t pixels[8]; 3486 uint8_t pixels[8];
3443 3487
3444 ResourceProvider::ResourceId id = resource_provider->CreateResource( 3488 ResourceProvider::ResourceId id = resource_provider->CreateResource(
3445 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, ETC1); 3489 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, ETC1);
3446 EXPECT_NE(0u, id); 3490 EXPECT_NE(0u, id);
3447 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); 3491 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
3448 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(3); 3492 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(3);
3449 EXPECT_CALL(*context, 3493 EXPECT_CALL(*context,
3450 compressedTexImage2D( 3494 compressedTexImage2D(
3451 _, 0, _, size.width(), size.height(), _, _, _)).Times(1); 3495 _, 0, _, size.width(), size.height(), _, _, _)).Times(1);
3452 resource_provider->SetPixels( 3496 resource_provider->SetPixels(
3453 id, pixels, gfx::Rect(size), gfx::Rect(size), gfx::Vector2d(0, 0)); 3497 id, pixels, gfx::Rect(size), gfx::Rect(size), gfx::Vector2d(0, 0));
3454 3498
3455 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); 3499 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
3493 size_t kTextureAllocationChunkSize = 1; 3537 size_t kTextureAllocationChunkSize = 1;
3494 scoped_ptr<ResourceProvider> resource_provider( 3538 scoped_ptr<ResourceProvider> resource_provider(
3495 ResourceProvider::Create(output_surface.get(), 3539 ResourceProvider::Create(output_surface.get(),
3496 shared_bitmap_manager.get(), 3540 shared_bitmap_manager.get(),
3497 0, 3541 0,
3498 false, 3542 false,
3499 kTextureAllocationChunkSize, 3543 kTextureAllocationChunkSize,
3500 false)); 3544 false));
3501 3545
3502 ResourceProvider::ResourceId id = resource_provider->CreateResource( 3546 ResourceProvider::ResourceId id = resource_provider->CreateResource(
3503 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 3547 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3504 resource_provider->AllocateForTesting(id); 3548 resource_provider->AllocateForTesting(id);
3505 Mock::VerifyAndClearExpectations(context); 3549 Mock::VerifyAndClearExpectations(context);
3506 3550
3507 DCHECK_EQ(2u, context->PeekTextureId()); 3551 DCHECK_EQ(2u, context->PeekTextureId());
3508 resource_provider->DeleteResource(id); 3552 resource_provider->DeleteResource(id);
3509 } 3553 }
3510 3554
3511 { 3555 {
3512 size_t kTextureAllocationChunkSize = 8; 3556 size_t kTextureAllocationChunkSize = 8;
3513 scoped_ptr<ResourceProvider> resource_provider( 3557 scoped_ptr<ResourceProvider> resource_provider(
3514 ResourceProvider::Create(output_surface.get(), 3558 ResourceProvider::Create(output_surface.get(),
3515 shared_bitmap_manager.get(), 3559 shared_bitmap_manager.get(),
3516 0, 3560 0,
3517 false, 3561 false,
3518 kTextureAllocationChunkSize, 3562 kTextureAllocationChunkSize,
3519 false)); 3563 false));
3520 3564
3521 ResourceProvider::ResourceId id = resource_provider->CreateResource( 3565 ResourceProvider::ResourceId id = resource_provider->CreateResource(
3522 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 3566 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3523 resource_provider->AllocateForTesting(id); 3567 resource_provider->AllocateForTesting(id);
3524 Mock::VerifyAndClearExpectations(context); 3568 Mock::VerifyAndClearExpectations(context);
3525 3569
3526 DCHECK_EQ(10u, context->PeekTextureId()); 3570 DCHECK_EQ(10u, context->PeekTextureId());
3527 resource_provider->DeleteResource(id); 3571 resource_provider->DeleteResource(id);
3528 } 3572 }
3529 } 3573 }
3530 3574
3531 } // namespace 3575 } // namespace
3532 } // namespace cc 3576 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/resource_provider.cc ('k') | cc/resources/scoped_resource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698