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

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: 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
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[3] = {
2479 ResourceProvider::TextureHintDefault,
2480 ResourceProvider::TextureHintImmutable,
2481 ResourceProvider::TextureHintFramebuffer,
2482 };
2483 for (int texture_id = 1; texture_id <= 3; ++texture_id) {
2484 // Check that the texture gets created with the right sampler settings.
2422 ResourceProvider::ResourceId id = 2485 ResourceProvider::ResourceId id =
2423 resource_provider->CreateGLTexture(size, 2486 resource_provider->CreateGLTexture(size,
2424 GL_TEXTURE_2D, 2487 GL_TEXTURE_2D,
2425 texture_pool, 2488 texture_pool,
2426 wrap_mode, 2489 GL_CLAMP_TO_EDGE,
2427 ResourceProvider::TextureUsageAny, 2490 hints[texture_id - 1],
2428 format); 2491 format);
2429 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)); 2492 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id));
2430 EXPECT_CALL(*context, 2493 EXPECT_CALL(*context,
2431 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); 2494 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
2432 EXPECT_CALL(*context, 2495 EXPECT_CALL(*context,
2433 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); 2496 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
2434 EXPECT_CALL( 2497 EXPECT_CALL(
2435 *context, 2498 *context,
2436 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_mode)); 2499 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
2437 EXPECT_CALL( 2500 EXPECT_CALL(
2438 *context, 2501 *context,
2439 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_mode)); 2502 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
2440 EXPECT_CALL(*context, 2503 EXPECT_CALL(*context,
2441 texParameteri(GL_TEXTURE_2D, 2504 texParameteri(GL_TEXTURE_2D,
2442 GL_TEXTURE_POOL_CHROMIUM, 2505 GL_TEXTURE_POOL_CHROMIUM,
2443 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM)); 2506 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM));
2507 // Check only TextureHintFramebuffer set GL_TEXTURE_USAGE_ANGLE.
2508 EXPECT_CALL(*context,
2509 texParameteri(GL_TEXTURE_2D,
2510 GL_TEXTURE_USAGE_ANGLE,
2511 GL_FRAMEBUFFER_ATTACHMENT_ANGLE))
2512 .Times(texture_id == 3 ? 1 : 0);
2444 resource_provider->CreateForTesting(id); 2513 resource_provider->CreateForTesting(id);
2445 EXPECT_NE(0u, id); 2514 EXPECT_NE(0u, id);
2446 2515
2447 Mock::VerifyAndClearExpectations(context); 2516 Mock::VerifyAndClearExpectations(context);
2448 } 2517 }
2449 } 2518 }
2450 2519
2451 TEST_P(ResourceProviderTest, TextureMailbox_SharedMemory) { 2520 TEST_P(ResourceProviderTest, TextureMailbox_SharedMemory) {
2452 if (GetParam() != ResourceProvider::Bitmap) 2521 if (GetParam() != ResourceProvider::Bitmap)
2453 return; 2522 return;
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
2816 gfx::Size size(2, 2); 2885 gfx::Size size(2, 2);
2817 gfx::Vector2d offset(0, 0); 2886 gfx::Vector2d offset(0, 0);
2818 gfx::Rect rect(0, 0, 2, 2); 2887 gfx::Rect rect(0, 0, 2, 2);
2819 ResourceFormat format = RGBA_8888; 2888 ResourceFormat format = RGBA_8888;
2820 ResourceProvider::ResourceId id = 0; 2889 ResourceProvider::ResourceId id = 0;
2821 uint8_t pixels[16] = { 0 }; 2890 uint8_t pixels[16] = { 0 };
2822 int texture_id = 123; 2891 int texture_id = 123;
2823 2892
2824 // Lazy allocation. Don't allocate when creating the resource. 2893 // Lazy allocation. Don't allocate when creating the resource.
2825 id = resource_provider->CreateResource( 2894 id = resource_provider->CreateResource(
2826 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 2895 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
2827 2896
2828 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); 2897 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
2829 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1); 2898 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1);
2830 resource_provider->CreateForTesting(id); 2899 resource_provider->CreateForTesting(id);
2831 2900
2832 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); 2901 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1);
2833 resource_provider->DeleteResource(id); 2902 resource_provider->DeleteResource(id);
2834 2903
2835 Mock::VerifyAndClearExpectations(context); 2904 Mock::VerifyAndClearExpectations(context);
2836 2905
2837 // Do allocate when we set the pixels. 2906 // Do allocate when we set the pixels.
2838 id = resource_provider->CreateResource( 2907 id = resource_provider->CreateResource(
2839 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 2908 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
2840 2909
2841 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); 2910 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
2842 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(3); 2911 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(3);
2843 EXPECT_CALL(*context, texImage2D(_, _, _, 2, 2, _, _, _, _)).Times(1); 2912 EXPECT_CALL(*context, texImage2D(_, _, _, 2, 2, _, _, _, _)).Times(1);
2844 EXPECT_CALL(*context, texSubImage2D(_, _, _, _, 2, 2, _, _, _)).Times(1); 2913 EXPECT_CALL(*context, texSubImage2D(_, _, _, _, 2, 2, _, _, _)).Times(1);
2845 resource_provider->SetPixels(id, pixels, rect, rect, offset); 2914 resource_provider->SetPixels(id, pixels, rect, rect, offset);
2846 2915
2847 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); 2916 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1);
2848 resource_provider->DeleteResource(id); 2917 resource_provider->DeleteResource(id);
2849 2918
2850 Mock::VerifyAndClearExpectations(context); 2919 Mock::VerifyAndClearExpectations(context);
2851 2920
2852 // Same for async version. 2921 // Same for async version.
2853 id = resource_provider->CreateResource( 2922 id = resource_provider->CreateResource(
2854 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 2923 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
2855 resource_provider->AcquirePixelRasterBuffer(id); 2924 resource_provider->AcquirePixelRasterBuffer(id);
2856 2925
2857 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); 2926 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
2858 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); 2927 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2);
2859 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) 2928 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _))
2860 .Times(1); 2929 .Times(1);
2861 resource_provider->BeginSetPixels(id); 2930 resource_provider->BeginSetPixels(id);
2862 ASSERT_TRUE(resource_provider->DidSetPixelsComplete(id)); 2931 ASSERT_TRUE(resource_provider->DidSetPixelsComplete(id));
2863 2932
2864 resource_provider->ReleasePixelRasterBuffer(id); 2933 resource_provider->ReleasePixelRasterBuffer(id);
2865 2934
2866 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); 2935 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1);
2867 resource_provider->DeleteResource(id); 2936 resource_provider->DeleteResource(id);
2868 2937
2869 Mock::VerifyAndClearExpectations(context); 2938 Mock::VerifyAndClearExpectations(context);
2870 } 2939 }
2871 2940
2872 TEST_P(ResourceProviderTest, TextureAllocationStorageUsageAny) { 2941 TEST_P(ResourceProviderTest, TextureAllocationHintImmutable) {
2873 // Only for GL textures. 2942 // Only for GL textures.
2874 if (GetParam() != ResourceProvider::GLTexture) 2943 if (GetParam() != ResourceProvider::GLTexture)
2875 return; 2944 return;
2876 scoped_ptr<AllocationTrackingContext3D> context_owned( 2945 scoped_ptr<AllocationTrackingContext3D> context_owned(
2877 new StrictMock<AllocationTrackingContext3D>); 2946 new StrictMock<AllocationTrackingContext3D>);
2878 AllocationTrackingContext3D* context = context_owned.get(); 2947 AllocationTrackingContext3D* context = context_owned.get();
2879 context->set_support_texture_storage(true); 2948 context->set_support_texture_storage(true);
2949 context->set_support_texture_usage(true);
2880 2950
2881 FakeOutputSurfaceClient output_surface_client; 2951 FakeOutputSurfaceClient output_surface_client;
2882 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( 2952 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
2883 context_owned.PassAs<TestWebGraphicsContext3D>())); 2953 context_owned.PassAs<TestWebGraphicsContext3D>()));
2884 CHECK(output_surface->BindToClient(&output_surface_client)); 2954 CHECK(output_surface->BindToClient(&output_surface_client));
2885 2955
2886 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( 2956 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
2887 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false)); 2957 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false));
2888 2958
2889 gfx::Size size(2, 2); 2959 gfx::Size size(2, 2);
2890 ResourceFormat format = RGBA_8888; 2960 ResourceFormat format = RGBA_8888;
2891 ResourceProvider::ResourceId id = 0; 2961 ResourceProvider::ResourceId id = 0;
2892 int texture_id = 123; 2962 int texture_id = 123;
2893 2963
2894 // Lazy allocation. Don't allocate when creating the resource. 2964 // Lazy allocation. Don't allocate when creating the resource.
2895 id = resource_provider->CreateResource( 2965 id = resource_provider->CreateResource(
2896 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 2966 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
2897 2967
2898 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); 2968 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
2899 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); 2969 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2);
2900 EXPECT_CALL(*context, texStorage2DEXT(_, _, _, 2, 2)).Times(1); 2970 EXPECT_CALL(*context, texStorage2DEXT(_, _, _, 2, 2)).Times(1);
2901 resource_provider->AllocateForTesting(id); 2971 resource_provider->AllocateForTesting(id);
2902 2972
2903 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); 2973 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1);
2904 resource_provider->DeleteResource(id); 2974 resource_provider->DeleteResource(id);
2905 2975
2906 Mock::VerifyAndClearExpectations(context); 2976 Mock::VerifyAndClearExpectations(context);
2907 } 2977 }
2908 2978
2909 TEST_P(ResourceProviderTest, TextureAllocationStorageUsageFramebuffer) { 2979 TEST_P(ResourceProviderTest, TextureAllocationHintDefault) {
2910 // Only for GL textures. 2980 // Only for GL textures.
2911 if (GetParam() != ResourceProvider::GLTexture) 2981 if (GetParam() != ResourceProvider::GLTexture)
2912 return; 2982 return;
2913 scoped_ptr<AllocationTrackingContext3D> context_owned( 2983 scoped_ptr<AllocationTrackingContext3D> context_owned(
2914 new StrictMock<AllocationTrackingContext3D>); 2984 new StrictMock<AllocationTrackingContext3D>);
2915 AllocationTrackingContext3D* context = context_owned.get(); 2985 AllocationTrackingContext3D* context = context_owned.get();
2916 context->set_support_texture_storage(true); 2986 context->set_support_texture_storage(true);
2987 context->set_support_texture_usage(true);
2917 2988
2918 FakeOutputSurfaceClient output_surface_client; 2989 FakeOutputSurfaceClient output_surface_client;
2919 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( 2990 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
2920 context_owned.PassAs<TestWebGraphicsContext3D>())); 2991 context_owned.PassAs<TestWebGraphicsContext3D>()));
2921 CHECK(output_surface->BindToClient(&output_surface_client)); 2992 CHECK(output_surface->BindToClient(&output_surface_client));
2922 2993
2923 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( 2994 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
2924 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false)); 2995 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false));
2925 2996
2926 gfx::Size size(2, 2); 2997 gfx::Size size(2, 2);
2927 ResourceFormat format = RGBA_8888; 2998 ResourceFormat format = RGBA_8888;
2928 ResourceProvider::ResourceId id = 0; 2999 ResourceProvider::ResourceId id = 0;
2929 int texture_id = 123; 3000 int texture_id = 123;
2930 3001
2931 // Lazy allocation. Don't allocate when creating the resource. 3002 // Lazy allocation. Don't allocate when creating the resource.
2932 id = resource_provider->CreateResource( 3003 id = resource_provider->CreateResource(
2933 size, 3004 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintDefault, format);
2934 GL_CLAMP_TO_EDGE,
2935 ResourceProvider::TextureUsageFramebuffer,
2936 format);
2937 3005
2938 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); 3006 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
2939 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); 3007 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2);
3008 EXPECT_CALL(*context, texImage2D(_, _, _, 2, 2, _, _, _, _)).Times(1);
3009 resource_provider->AllocateForTesting(id);
3010
3011 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1);
3012 resource_provider->DeleteResource(id);
3013
3014 Mock::VerifyAndClearExpectations(context);
3015 }
3016
3017 TEST_P(ResourceProviderTest, TextureAllocationHintFramebuffer) {
3018 // Only for GL textures.
3019 if (GetParam() != ResourceProvider::GLTexture)
3020 return;
3021 scoped_ptr<AllocationTrackingContext3D> context_owned(
3022 new StrictMock<AllocationTrackingContext3D>);
3023 AllocationTrackingContext3D* context = context_owned.get();
3024 context->set_support_texture_storage(true);
3025 context->set_support_texture_usage(true);
3026
3027 FakeOutputSurfaceClient output_surface_client;
3028 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
3029 context_owned.PassAs<TestWebGraphicsContext3D>()));
3030 CHECK(output_surface->BindToClient(&output_surface_client));
3031
3032 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
3033 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false));
3034
3035 gfx::Size size(2, 2);
3036 ResourceFormat format = RGBA_8888;
3037 ResourceProvider::ResourceId id = 0;
3038 int texture_id = 123;
3039
3040 // Lazy allocation. Don't allocate when creating the resource.
3041 id = resource_provider->CreateResource(
3042 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintFramebuffer, format);
3043
3044 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
3045 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2);
2940 EXPECT_CALL(*context, texImage2D(_, _, _, 2, 2, _, _, _, _)).Times(1); 3046 EXPECT_CALL(*context, texImage2D(_, _, _, 2, 2, _, _, _, _)).Times(1);
2941 resource_provider->AllocateForTesting(id); 3047 resource_provider->AllocateForTesting(id);
2942 3048
2943 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); 3049 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1);
2944 resource_provider->DeleteResource(id); 3050 resource_provider->DeleteResource(id);
2945 3051
2946 Mock::VerifyAndClearExpectations(context); 3052 Mock::VerifyAndClearExpectations(context);
2947 } 3053 }
2948 3054
2949 TEST_P(ResourceProviderTest, PixelBuffer_GLTexture) { 3055 TEST_P(ResourceProviderTest, PixelBuffer_GLTexture) {
(...skipping 10 matching lines...) Expand all
2960 3066
2961 gfx::Size size(2, 2); 3067 gfx::Size size(2, 2);
2962 ResourceFormat format = RGBA_8888; 3068 ResourceFormat format = RGBA_8888;
2963 ResourceProvider::ResourceId id = 0; 3069 ResourceProvider::ResourceId id = 0;
2964 int texture_id = 123; 3070 int texture_id = 123;
2965 3071
2966 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( 3072 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
2967 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false)); 3073 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false));
2968 3074
2969 id = resource_provider->CreateResource( 3075 id = resource_provider->CreateResource(
2970 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 3076 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
2971 resource_provider->AcquirePixelRasterBuffer(id); 3077 resource_provider->AcquirePixelRasterBuffer(id);
2972 3078
2973 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); 3079 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
2974 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); 3080 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2);
2975 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) 3081 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _))
2976 .Times(1); 3082 .Times(1);
2977 resource_provider->BeginSetPixels(id); 3083 resource_provider->BeginSetPixels(id);
2978 3084
2979 EXPECT_TRUE(resource_provider->DidSetPixelsComplete(id)); 3085 EXPECT_TRUE(resource_provider->DidSetPixelsComplete(id));
2980 3086
(...skipping 20 matching lines...) Expand all
3001 3107
3002 gfx::Size size(2, 2); 3108 gfx::Size size(2, 2);
3003 ResourceFormat format = RGBA_8888; 3109 ResourceFormat format = RGBA_8888;
3004 ResourceProvider::ResourceId id = 0; 3110 ResourceProvider::ResourceId id = 0;
3005 int texture_id = 123; 3111 int texture_id = 123;
3006 3112
3007 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( 3113 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
3008 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false)); 3114 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false));
3009 3115
3010 id = resource_provider->CreateResource( 3116 id = resource_provider->CreateResource(
3011 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 3117 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3012 resource_provider->AcquirePixelRasterBuffer(id); 3118 resource_provider->AcquirePixelRasterBuffer(id);
3013 3119
3014 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); 3120 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
3015 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); 3121 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2);
3016 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) 3122 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _))
3017 .Times(1); 3123 .Times(1);
3018 resource_provider->BeginSetPixels(id); 3124 resource_provider->BeginSetPixels(id);
3019 3125
3020 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1); 3126 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1);
3021 EXPECT_CALL(*context, waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)).Times(1); 3127 EXPECT_CALL(*context, waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)).Times(1);
(...skipping 22 matching lines...) Expand all
3044 ResourceFormat format = RGBA_8888; 3150 ResourceFormat format = RGBA_8888;
3045 ResourceProvider::ResourceId id = 0; 3151 ResourceProvider::ResourceId id = 0;
3046 int texture_id = 123; 3152 int texture_id = 123;
3047 3153
3048 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( 3154 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
3049 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false)); 3155 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false));
3050 3156
3051 EXPECT_CALL(*context, NextTextureId()).WillRepeatedly(Return(texture_id)); 3157 EXPECT_CALL(*context, NextTextureId()).WillRepeatedly(Return(texture_id));
3052 3158
3053 id = resource_provider->CreateResource( 3159 id = resource_provider->CreateResource(
3054 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 3160 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3055 context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, 3161 context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
3056 GL_INNOCENT_CONTEXT_RESET_ARB); 3162 GL_INNOCENT_CONTEXT_RESET_ARB);
3057 3163
3058 resource_provider->AcquirePixelRasterBuffer(id); 3164 resource_provider->AcquirePixelRasterBuffer(id);
3059 SkCanvas* raster_canvas = resource_provider->MapPixelRasterBuffer(id); 3165 SkCanvas* raster_canvas = resource_provider->MapPixelRasterBuffer(id);
3060 EXPECT_TRUE(raster_canvas == NULL); 3166 EXPECT_TRUE(raster_canvas == NULL);
3061 resource_provider->UnmapPixelRasterBuffer(id); 3167 resource_provider->UnmapPixelRasterBuffer(id);
3062 resource_provider->ReleasePixelRasterBuffer(id); 3168 resource_provider->ReleasePixelRasterBuffer(id);
3063 Mock::VerifyAndClearExpectations(context); 3169 Mock::VerifyAndClearExpectations(context);
3064 } 3170 }
(...skipping 16 matching lines...) Expand all
3081 gfx::Size size(kWidth, kHeight); 3187 gfx::Size size(kWidth, kHeight);
3082 ResourceFormat format = RGBA_8888; 3188 ResourceFormat format = RGBA_8888;
3083 ResourceProvider::ResourceId id = 0; 3189 ResourceProvider::ResourceId id = 0;
3084 const unsigned kTextureId = 123u; 3190 const unsigned kTextureId = 123u;
3085 const unsigned kImageId = 234u; 3191 const unsigned kImageId = 234u;
3086 3192
3087 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( 3193 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
3088 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false)); 3194 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false));
3089 3195
3090 id = resource_provider->CreateResource( 3196 id = resource_provider->CreateResource(
3091 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 3197 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3092 3198
3093 const int kStride = 4; 3199 const int kStride = 4;
3094 void* dummy_mapped_buffer_address = NULL; 3200 void* dummy_mapped_buffer_address = NULL;
3095 EXPECT_CALL( 3201 EXPECT_CALL(
3096 *context, 3202 *context,
3097 createImageCHROMIUM(kWidth, kHeight, GL_RGBA8_OES, GL_IMAGE_MAP_CHROMIUM)) 3203 createImageCHROMIUM(kWidth, kHeight, GL_RGBA8_OES, GL_IMAGE_MAP_CHROMIUM))
3098 .WillOnce(Return(kImageId)) 3204 .WillOnce(Return(kImageId))
3099 .RetiresOnSaturation(); 3205 .RetiresOnSaturation();
3100 EXPECT_CALL(*context, getImageParameterivCHROMIUM(kImageId, 3206 EXPECT_CALL(*context, getImageParameterivCHROMIUM(kImageId,
3101 GL_IMAGE_ROWBYTES_CHROMIUM, 3207 GL_IMAGE_ROWBYTES_CHROMIUM,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
3175 3281
3176 gfx::Size size(1, 1); 3282 gfx::Size size(1, 1);
3177 ResourceFormat format = RGBA_8888; 3283 ResourceFormat format = RGBA_8888;
3178 ResourceProvider::ResourceId id = 0; 3284 ResourceProvider::ResourceId id = 0;
3179 const uint32_t kBadBeef = 0xbadbeef; 3285 const uint32_t kBadBeef = 0xbadbeef;
3180 3286
3181 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( 3287 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
3182 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false)); 3288 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false));
3183 3289
3184 id = resource_provider->CreateResource( 3290 id = resource_provider->CreateResource(
3185 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 3291 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3186 3292
3187 SkBitmap bitmap; 3293 SkBitmap bitmap;
3188 bitmap.allocN32Pixels(size.width(), size.height()); 3294 bitmap.allocN32Pixels(size.width(), size.height());
3189 *(bitmap.getAddr32(0, 0)) = kBadBeef; 3295 *(bitmap.getAddr32(0, 0)) = kBadBeef;
3190 SkCanvas* canvas = resource_provider->MapImageRasterBuffer(id); 3296 SkCanvas* canvas = resource_provider->MapImageRasterBuffer(id);
3191 ASSERT_TRUE(!!canvas); 3297 ASSERT_TRUE(!!canvas);
3192 canvas->writePixels(bitmap, 0, 0); 3298 canvas->writePixels(bitmap, 0, 0);
3193 resource_provider->UnmapImageRasterBuffer(id); 3299 resource_provider->UnmapImageRasterBuffer(id);
3194 3300
3195 { 3301 {
(...skipping 27 matching lines...) Expand all
3223 ResourceProvider::ResourceId source_id = 0; 3329 ResourceProvider::ResourceId source_id = 0;
3224 ResourceProvider::ResourceId dest_id = 0; 3330 ResourceProvider::ResourceId dest_id = 0;
3225 const unsigned kSourceTextureId = 123u; 3331 const unsigned kSourceTextureId = 123u;
3226 const unsigned kDestTextureId = 321u; 3332 const unsigned kDestTextureId = 321u;
3227 const unsigned kImageId = 234u; 3333 const unsigned kImageId = 234u;
3228 3334
3229 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( 3335 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
3230 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false)); 3336 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false));
3231 3337
3232 source_id = resource_provider->CreateResource( 3338 source_id = resource_provider->CreateResource(
3233 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 3339 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3234 3340
3235 const int kStride = 4; 3341 const int kStride = 4;
3236 void* dummy_mapped_buffer_address = NULL; 3342 void* dummy_mapped_buffer_address = NULL;
3237 EXPECT_CALL( 3343 EXPECT_CALL(
3238 *context, 3344 *context,
3239 createImageCHROMIUM(kWidth, kHeight, GL_RGBA8_OES, GL_IMAGE_MAP_CHROMIUM)) 3345 createImageCHROMIUM(kWidth, kHeight, GL_RGBA8_OES, GL_IMAGE_MAP_CHROMIUM))
3240 .WillOnce(Return(kImageId)) 3346 .WillOnce(Return(kImageId))
3241 .RetiresOnSaturation(); 3347 .RetiresOnSaturation();
3242 EXPECT_CALL( 3348 EXPECT_CALL(
3243 *context, 3349 *context,
3244 getImageParameterivCHROMIUM(kImageId, GL_IMAGE_ROWBYTES_CHROMIUM, _)) 3350 getImageParameterivCHROMIUM(kImageId, GL_IMAGE_ROWBYTES_CHROMIUM, _))
3245 .WillOnce(SetArgPointee<2>(kStride)) 3351 .WillOnce(SetArgPointee<2>(kStride))
3246 .RetiresOnSaturation(); 3352 .RetiresOnSaturation();
3247 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId)) 3353 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId))
3248 .WillOnce(Return(dummy_mapped_buffer_address)) 3354 .WillOnce(Return(dummy_mapped_buffer_address))
3249 .RetiresOnSaturation(); 3355 .RetiresOnSaturation();
3250 resource_provider->MapImageRasterBuffer(source_id); 3356 resource_provider->MapImageRasterBuffer(source_id);
3251 Mock::VerifyAndClearExpectations(context); 3357 Mock::VerifyAndClearExpectations(context);
3252 3358
3253 EXPECT_CALL(*context, unmapImageCHROMIUM(kImageId)) 3359 EXPECT_CALL(*context, unmapImageCHROMIUM(kImageId))
3254 .Times(1) 3360 .Times(1)
3255 .RetiresOnSaturation(); 3361 .RetiresOnSaturation();
3256 resource_provider->UnmapImageRasterBuffer(source_id); 3362 resource_provider->UnmapImageRasterBuffer(source_id);
3257 Mock::VerifyAndClearExpectations(context); 3363 Mock::VerifyAndClearExpectations(context);
3258 3364
3259 dest_id = resource_provider->CreateResource( 3365 dest_id = resource_provider->CreateResource(
3260 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 3366 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3261 3367
3262 EXPECT_CALL(*context, NextTextureId()) 3368 EXPECT_CALL(*context, NextTextureId())
3263 .WillOnce(Return(kDestTextureId)) 3369 .WillOnce(Return(kDestTextureId))
3264 .RetiresOnSaturation(); 3370 .RetiresOnSaturation();
3265 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kDestTextureId)) 3371 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kDestTextureId))
3266 .Times(1) 3372 .Times(1)
3267 .RetiresOnSaturation(); 3373 .RetiresOnSaturation();
3268 EXPECT_CALL(*context, NextTextureId()) 3374 EXPECT_CALL(*context, NextTextureId())
3269 .WillOnce(Return(kSourceTextureId)) 3375 .WillOnce(Return(kSourceTextureId))
3270 .RetiresOnSaturation(); 3376 .RetiresOnSaturation();
(...skipping 30 matching lines...) Expand all
3301 gfx::Size size(1, 1); 3407 gfx::Size size(1, 1);
3302 ResourceFormat format = RGBA_8888; 3408 ResourceFormat format = RGBA_8888;
3303 ResourceProvider::ResourceId source_id = 0; 3409 ResourceProvider::ResourceId source_id = 0;
3304 ResourceProvider::ResourceId dest_id = 0; 3410 ResourceProvider::ResourceId dest_id = 0;
3305 const uint32_t kBadBeef = 0xbadbeef; 3411 const uint32_t kBadBeef = 0xbadbeef;
3306 3412
3307 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( 3413 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
3308 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false)); 3414 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false));
3309 3415
3310 source_id = resource_provider->CreateResource( 3416 source_id = resource_provider->CreateResource(
3311 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 3417 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3312 3418
3313 SkBitmap bitmap; 3419 SkBitmap bitmap;
3314 bitmap.allocN32Pixels(size.width(), size.height()); 3420 bitmap.allocN32Pixels(size.width(), size.height());
3315 *(bitmap.getAddr32(0, 0)) = kBadBeef; 3421 *(bitmap.getAddr32(0, 0)) = kBadBeef;
3316 SkCanvas* canvas = resource_provider->MapImageRasterBuffer(source_id); 3422 SkCanvas* canvas = resource_provider->MapImageRasterBuffer(source_id);
3317 ASSERT_TRUE(!!canvas); 3423 ASSERT_TRUE(!!canvas);
3318 canvas->writePixels(bitmap, 0, 0); 3424 canvas->writePixels(bitmap, 0, 0);
3319 resource_provider->UnmapImageRasterBuffer(source_id); 3425 resource_provider->UnmapImageRasterBuffer(source_id);
3320 3426
3321 dest_id = resource_provider->CreateResource( 3427 dest_id = resource_provider->CreateResource(
3322 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 3428 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3323 3429
3324 resource_provider->CopyResource(source_id, dest_id); 3430 resource_provider->CopyResource(source_id, dest_id);
3325 3431
3326 { 3432 {
3327 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(), 3433 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(),
3328 dest_id); 3434 dest_id);
3329 const SkBitmap* sk_bitmap = lock.sk_bitmap(); 3435 const SkBitmap* sk_bitmap = lock.sk_bitmap();
3330 EXPECT_EQ(sk_bitmap->width(), size.width()); 3436 EXPECT_EQ(sk_bitmap->width(), size.width());
3331 EXPECT_EQ(sk_bitmap->height(), size.height()); 3437 EXPECT_EQ(sk_bitmap->height(), size.height());
3332 EXPECT_EQ(*sk_bitmap->getAddr32(0, 0), kBadBeef); 3438 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( 3505 scoped_ptr<ResourceProvider> resource_provider(
3400 ResourceProvider::Create(output_surface.get(), 3506 ResourceProvider::Create(output_surface.get(),
3401 shared_bitmap_manager_.get(), 3507 shared_bitmap_manager_.get(),
3402 0, 3508 0,
3403 false, 3509 false,
3404 1, 3510 1,
3405 false)); 3511 false));
3406 int texture_id = 123; 3512 int texture_id = 123;
3407 3513
3408 ResourceProvider::ResourceId id = resource_provider->CreateResource( 3514 ResourceProvider::ResourceId id = resource_provider->CreateResource(
3409 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, ETC1); 3515 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, ETC1);
3410 EXPECT_NE(0u, id); 3516 EXPECT_NE(0u, id);
3411 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); 3517 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
3412 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); 3518 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2);
3413 resource_provider->AllocateForTesting(id); 3519 resource_provider->AllocateForTesting(id);
3414 3520
3415 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); 3521 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1);
3416 resource_provider->DeleteResource(id); 3522 resource_provider->DeleteResource(id);
3417 } 3523 }
3418 3524
3419 TEST_P(ResourceProviderTest, CompressedTextureETC1SetPixels) { 3525 TEST_P(ResourceProviderTest, CompressedTextureETC1SetPixels) {
(...skipping 15 matching lines...) Expand all
3435 ResourceProvider::Create(output_surface.get(), 3541 ResourceProvider::Create(output_surface.get(),
3436 shared_bitmap_manager_.get(), 3542 shared_bitmap_manager_.get(),
3437 0, 3543 0,
3438 false, 3544 false,
3439 1, 3545 1,
3440 false)); 3546 false));
3441 int texture_id = 123; 3547 int texture_id = 123;
3442 uint8_t pixels[8]; 3548 uint8_t pixels[8];
3443 3549
3444 ResourceProvider::ResourceId id = resource_provider->CreateResource( 3550 ResourceProvider::ResourceId id = resource_provider->CreateResource(
3445 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, ETC1); 3551 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, ETC1);
3446 EXPECT_NE(0u, id); 3552 EXPECT_NE(0u, id);
3447 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); 3553 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
3448 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(3); 3554 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(3);
3449 EXPECT_CALL(*context, 3555 EXPECT_CALL(*context,
3450 compressedTexImage2D( 3556 compressedTexImage2D(
3451 _, 0, _, size.width(), size.height(), _, _, _)).Times(1); 3557 _, 0, _, size.width(), size.height(), _, _, _)).Times(1);
3452 resource_provider->SetPixels( 3558 resource_provider->SetPixels(
3453 id, pixels, gfx::Rect(size), gfx::Rect(size), gfx::Vector2d(0, 0)); 3559 id, pixels, gfx::Rect(size), gfx::Rect(size), gfx::Vector2d(0, 0));
3454 3560
3455 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); 3561 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; 3599 size_t kTextureAllocationChunkSize = 1;
3494 scoped_ptr<ResourceProvider> resource_provider( 3600 scoped_ptr<ResourceProvider> resource_provider(
3495 ResourceProvider::Create(output_surface.get(), 3601 ResourceProvider::Create(output_surface.get(),
3496 shared_bitmap_manager.get(), 3602 shared_bitmap_manager.get(),
3497 0, 3603 0,
3498 false, 3604 false,
3499 kTextureAllocationChunkSize, 3605 kTextureAllocationChunkSize,
3500 false)); 3606 false));
3501 3607
3502 ResourceProvider::ResourceId id = resource_provider->CreateResource( 3608 ResourceProvider::ResourceId id = resource_provider->CreateResource(
3503 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 3609 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3504 resource_provider->AllocateForTesting(id); 3610 resource_provider->AllocateForTesting(id);
3505 Mock::VerifyAndClearExpectations(context); 3611 Mock::VerifyAndClearExpectations(context);
3506 3612
3507 DCHECK_EQ(2u, context->PeekTextureId()); 3613 DCHECK_EQ(2u, context->PeekTextureId());
3508 resource_provider->DeleteResource(id); 3614 resource_provider->DeleteResource(id);
3509 } 3615 }
3510 3616
3511 { 3617 {
3512 size_t kTextureAllocationChunkSize = 8; 3618 size_t kTextureAllocationChunkSize = 8;
3513 scoped_ptr<ResourceProvider> resource_provider( 3619 scoped_ptr<ResourceProvider> resource_provider(
3514 ResourceProvider::Create(output_surface.get(), 3620 ResourceProvider::Create(output_surface.get(),
3515 shared_bitmap_manager.get(), 3621 shared_bitmap_manager.get(),
3516 0, 3622 0,
3517 false, 3623 false,
3518 kTextureAllocationChunkSize, 3624 kTextureAllocationChunkSize,
3519 false)); 3625 false));
3520 3626
3521 ResourceProvider::ResourceId id = resource_provider->CreateResource( 3627 ResourceProvider::ResourceId id = resource_provider->CreateResource(
3522 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); 3628 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3523 resource_provider->AllocateForTesting(id); 3629 resource_provider->AllocateForTesting(id);
3524 Mock::VerifyAndClearExpectations(context); 3630 Mock::VerifyAndClearExpectations(context);
3525 3631
3526 DCHECK_EQ(10u, context->PeekTextureId()); 3632 DCHECK_EQ(10u, context->PeekTextureId());
3527 resource_provider->DeleteResource(id); 3633 resource_provider->DeleteResource(id);
3528 } 3634 }
3529 } 3635 }
3530 3636
3531 } // namespace 3637 } // namespace
3532 } // namespace cc 3638 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698