| OLD | NEW |
| 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 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 ResourceProvider* resource_provider, | 425 ResourceProvider* resource_provider, |
| 426 ResourceProviderContext* context) { | 426 ResourceProviderContext* context) { |
| 427 DCHECK_EQ(expected_default_type, resource_provider->default_resource_type()); | 427 DCHECK_EQ(expected_default_type, resource_provider->default_resource_type()); |
| 428 | 428 |
| 429 gfx::Size size(1, 1); | 429 gfx::Size size(1, 1); |
| 430 WGC3Denum format = GL_RGBA; | 430 WGC3Denum format = GL_RGBA; |
| 431 size_t pixel_size = TextureSize(size, format); | 431 size_t pixel_size = TextureSize(size, format); |
| 432 ASSERT_EQ(4U, pixel_size); | 432 ASSERT_EQ(4U, pixel_size); |
| 433 | 433 |
| 434 ResourceProvider::ResourceId id = resource_provider->CreateResource( | 434 ResourceProvider::ResourceId id = resource_provider->CreateResource( |
| 435 size, format, ResourceProvider::TextureUsageAny); | 435 size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny); |
| 436 EXPECT_EQ(1, static_cast<int>(resource_provider->num_resources())); | 436 EXPECT_EQ(1, static_cast<int>(resource_provider->num_resources())); |
| 437 if (expected_default_type == ResourceProvider::GLTexture) | 437 if (expected_default_type == ResourceProvider::GLTexture) |
| 438 EXPECT_EQ(0, context->texture_count()); | 438 EXPECT_EQ(0, context->texture_count()); |
| 439 | 439 |
| 440 uint8_t data[4] = { 1, 2, 3, 4 }; | 440 uint8_t data[4] = { 1, 2, 3, 4 }; |
| 441 gfx::Rect rect(size); | 441 gfx::Rect rect(size); |
| 442 resource_provider->SetPixels(id, data, rect, rect, gfx::Vector2d()); | 442 resource_provider->SetPixels(id, data, rect, rect, gfx::Vector2d()); |
| 443 if (expected_default_type == ResourceProvider::GLTexture) | 443 if (expected_default_type == ResourceProvider::GLTexture) |
| 444 EXPECT_EQ(1, context->texture_count()); | 444 EXPECT_EQ(1, context->texture_count()); |
| 445 | 445 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 457 CheckCreateResource(GetParam(), resource_provider_.get(), context()); | 457 CheckCreateResource(GetParam(), resource_provider_.get(), context()); |
| 458 } | 458 } |
| 459 | 459 |
| 460 TEST_P(ResourceProviderTest, Upload) { | 460 TEST_P(ResourceProviderTest, Upload) { |
| 461 gfx::Size size(2, 2); | 461 gfx::Size size(2, 2); |
| 462 WGC3Denum format = GL_RGBA; | 462 WGC3Denum format = GL_RGBA; |
| 463 size_t pixel_size = TextureSize(size, format); | 463 size_t pixel_size = TextureSize(size, format); |
| 464 ASSERT_EQ(16U, pixel_size); | 464 ASSERT_EQ(16U, pixel_size); |
| 465 | 465 |
| 466 ResourceProvider::ResourceId id = resource_provider_->CreateResource( | 466 ResourceProvider::ResourceId id = resource_provider_->CreateResource( |
| 467 size, format, ResourceProvider::TextureUsageAny); | 467 size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny); |
| 468 | 468 |
| 469 uint8_t image[16] = { 0 }; | 469 uint8_t image[16] = { 0 }; |
| 470 gfx::Rect image_rect(size); | 470 gfx::Rect image_rect(size); |
| 471 resource_provider_->SetPixels( | 471 resource_provider_->SetPixels( |
| 472 id, image, image_rect, image_rect, gfx::Vector2d()); | 472 id, image, image_rect, image_rect, gfx::Vector2d()); |
| 473 | 473 |
| 474 for (uint8_t i = 0; i < pixel_size; ++i) | 474 for (uint8_t i = 0; i < pixel_size; ++i) |
| 475 image[i] = i; | 475 image[i] = i; |
| 476 | 476 |
| 477 uint8_t result[16] = { 0 }; | 477 uint8_t result[16] = { 0 }; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 | 541 |
| 542 scoped_ptr<ResourceProvider> child_resource_provider( | 542 scoped_ptr<ResourceProvider> child_resource_provider( |
| 543 ResourceProvider::Create(child_output_surface.get(), 0)); | 543 ResourceProvider::Create(child_output_surface.get(), 0)); |
| 544 | 544 |
| 545 gfx::Size size(1, 1); | 545 gfx::Size size(1, 1); |
| 546 WGC3Denum format = GL_RGBA; | 546 WGC3Denum format = GL_RGBA; |
| 547 size_t pixel_size = TextureSize(size, format); | 547 size_t pixel_size = TextureSize(size, format); |
| 548 ASSERT_EQ(4U, pixel_size); | 548 ASSERT_EQ(4U, pixel_size); |
| 549 | 549 |
| 550 ResourceProvider::ResourceId id1 = child_resource_provider->CreateResource( | 550 ResourceProvider::ResourceId id1 = child_resource_provider->CreateResource( |
| 551 size, format, ResourceProvider::TextureUsageAny); | 551 size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny); |
| 552 uint8_t data1[4] = { 1, 2, 3, 4 }; | 552 uint8_t data1[4] = { 1, 2, 3, 4 }; |
| 553 gfx::Rect rect(size); | 553 gfx::Rect rect(size); |
| 554 child_resource_provider->SetPixels(id1, data1, rect, rect, gfx::Vector2d()); | 554 child_resource_provider->SetPixels(id1, data1, rect, rect, gfx::Vector2d()); |
| 555 | 555 |
| 556 ResourceProvider::ResourceId id2 = child_resource_provider->CreateResource( | 556 ResourceProvider::ResourceId id2 = child_resource_provider->CreateResource( |
| 557 size, format, ResourceProvider::TextureUsageAny); | 557 size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny); |
| 558 uint8_t data2[4] = { 5, 5, 5, 5 }; | 558 uint8_t data2[4] = { 5, 5, 5, 5 }; |
| 559 child_resource_provider->SetPixels(id2, data2, rect, rect, gfx::Vector2d()); | 559 child_resource_provider->SetPixels(id2, data2, rect, rect, gfx::Vector2d()); |
| 560 | 560 |
| 561 int child_id = resource_provider_->CreateChild(); | 561 int child_id = resource_provider_->CreateChild(); |
| 562 { | 562 { |
| 563 // Transfer some resources to the parent. | 563 // Transfer some resources to the parent. |
| 564 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 564 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
| 565 resource_ids_to_transfer.push_back(id1); | 565 resource_ids_to_transfer.push_back(id1); |
| 566 resource_ids_to_transfer.push_back(id2); | 566 resource_ids_to_transfer.push_back(id2); |
| 567 TransferableResourceArray list; | 567 TransferableResourceArray list; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 | 677 |
| 678 scoped_ptr<ResourceProvider> child_resource_provider( | 678 scoped_ptr<ResourceProvider> child_resource_provider( |
| 679 ResourceProvider::Create(child_output_surface.get(), 0)); | 679 ResourceProvider::Create(child_output_surface.get(), 0)); |
| 680 | 680 |
| 681 gfx::Size size(1, 1); | 681 gfx::Size size(1, 1); |
| 682 WGC3Denum format = GL_RGBA; | 682 WGC3Denum format = GL_RGBA; |
| 683 size_t pixel_size = TextureSize(size, format); | 683 size_t pixel_size = TextureSize(size, format); |
| 684 ASSERT_EQ(4U, pixel_size); | 684 ASSERT_EQ(4U, pixel_size); |
| 685 | 685 |
| 686 ResourceProvider::ResourceId id = child_resource_provider->CreateResource( | 686 ResourceProvider::ResourceId id = child_resource_provider->CreateResource( |
| 687 size, format, ResourceProvider::TextureUsageAny); | 687 size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny); |
| 688 uint8_t data[4] = { 1, 2, 3, 4 }; | 688 uint8_t data[4] = { 1, 2, 3, 4 }; |
| 689 gfx::Rect rect(size); | 689 gfx::Rect rect(size); |
| 690 child_resource_provider->SetPixels(id, data, rect, rect, gfx::Vector2d()); | 690 child_resource_provider->SetPixels(id, data, rect, rect, gfx::Vector2d()); |
| 691 | 691 |
| 692 int child_id = resource_provider_->CreateChild(); | 692 int child_id = resource_provider_->CreateChild(); |
| 693 { | 693 { |
| 694 // Transfer some resource to the parent. | 694 // Transfer some resource to the parent. |
| 695 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 695 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
| 696 resource_ids_to_transfer.push_back(id); | 696 resource_ids_to_transfer.push_back(id); |
| 697 TransferableResourceArray list; | 697 TransferableResourceArray list; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 | 740 |
| 741 scoped_ptr<ResourceProvider> child_resource_provider( | 741 scoped_ptr<ResourceProvider> child_resource_provider( |
| 742 ResourceProvider::Create(child_output_surface.get(), 0)); | 742 ResourceProvider::Create(child_output_surface.get(), 0)); |
| 743 | 743 |
| 744 gfx::Size size(1, 1); | 744 gfx::Size size(1, 1); |
| 745 WGC3Denum format = GL_RGBA; | 745 WGC3Denum format = GL_RGBA; |
| 746 size_t pixel_size = TextureSize(size, format); | 746 size_t pixel_size = TextureSize(size, format); |
| 747 ASSERT_EQ(4U, pixel_size); | 747 ASSERT_EQ(4U, pixel_size); |
| 748 | 748 |
| 749 ResourceProvider::ResourceId id = child_resource_provider->CreateResource( | 749 ResourceProvider::ResourceId id = child_resource_provider->CreateResource( |
| 750 size, format, ResourceProvider::TextureUsageAny); | 750 size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny); |
| 751 uint8_t data[4] = { 1, 2, 3, 4 }; | 751 uint8_t data[4] = { 1, 2, 3, 4 }; |
| 752 gfx::Rect rect(size); | 752 gfx::Rect rect(size); |
| 753 child_resource_provider->SetPixels(id, data, rect, rect, gfx::Vector2d()); | 753 child_resource_provider->SetPixels(id, data, rect, rect, gfx::Vector2d()); |
| 754 EXPECT_EQ(static_cast<unsigned>(GL_LINEAR), | 754 EXPECT_EQ(static_cast<unsigned>(GL_LINEAR), |
| 755 GetResourceFilter(child_resource_provider.get(), | 755 GetResourceFilter(child_resource_provider.get(), |
| 756 child_context, | 756 child_context, |
| 757 id)); | 757 id)); |
| 758 SetResourceFilter(child_resource_provider.get(), id, GL_NEAREST); | 758 SetResourceFilter(child_resource_provider.get(), id, GL_NEAREST); |
| 759 EXPECT_EQ(static_cast<unsigned>(GL_NEAREST), | 759 EXPECT_EQ(static_cast<unsigned>(GL_NEAREST), |
| 760 GetResourceFilter(child_resource_provider.get(), | 760 GetResourceFilter(child_resource_provider.get(), |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1107 *context, | 1107 *context, |
| 1108 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); | 1108 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); |
| 1109 EXPECT_CALL( | 1109 EXPECT_CALL( |
| 1110 *context, | 1110 *context, |
| 1111 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); | 1111 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); |
| 1112 EXPECT_CALL(*context, | 1112 EXPECT_CALL(*context, |
| 1113 texParameteri(GL_TEXTURE_2D, | 1113 texParameteri(GL_TEXTURE_2D, |
| 1114 GL_TEXTURE_POOL_CHROMIUM, | 1114 GL_TEXTURE_POOL_CHROMIUM, |
| 1115 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM)); | 1115 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM)); |
| 1116 ResourceProvider::ResourceId id = resource_provider->CreateResource( | 1116 ResourceProvider::ResourceId id = resource_provider->CreateResource( |
| 1117 size, format, ResourceProvider::TextureUsageAny); | 1117 size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny); |
| 1118 resource_provider->AllocateForTesting(id); | 1118 resource_provider->AllocateForTesting(id); |
| 1119 | 1119 |
| 1120 // Creating a sampler with the default filter should not change any texture | 1120 // Creating a sampler with the default filter should not change any texture |
| 1121 // parameters. | 1121 // parameters. |
| 1122 { | 1122 { |
| 1123 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)); | 1123 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)); |
| 1124 ResourceProvider::ScopedSamplerGL sampler( | 1124 ResourceProvider::ScopedSamplerGL sampler( |
| 1125 resource_provider.get(), id, GL_TEXTURE_2D, GL_LINEAR); | 1125 resource_provider.get(), id, GL_TEXTURE_2D, GL_LINEAR); |
| 1126 } | 1126 } |
| 1127 | 1127 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1168 | 1168 |
| 1169 scoped_ptr<ResourceProvider> resource_provider( | 1169 scoped_ptr<ResourceProvider> resource_provider( |
| 1170 ResourceProvider::Create(output_surface.get(), 0)); | 1170 ResourceProvider::Create(output_surface.get(), 0)); |
| 1171 | 1171 |
| 1172 gfx::Size size(1, 1); | 1172 gfx::Size size(1, 1); |
| 1173 WGC3Denum format = GL_RGBA; | 1173 WGC3Denum format = GL_RGBA; |
| 1174 int texture_id = 1; | 1174 int texture_id = 1; |
| 1175 | 1175 |
| 1176 // Check that the texture gets created with the right sampler settings. | 1176 // Check that the texture gets created with the right sampler settings. |
| 1177 ResourceProvider::ResourceId id = resource_provider->CreateManagedResource( | 1177 ResourceProvider::ResourceId id = resource_provider->CreateManagedResource( |
| 1178 size, format, ResourceProvider::TextureUsageAny); | 1178 size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny); |
| 1179 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)); | 1179 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)); |
| 1180 EXPECT_CALL(*context, | 1180 EXPECT_CALL(*context, |
| 1181 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); | 1181 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); |
| 1182 EXPECT_CALL(*context, | 1182 EXPECT_CALL(*context, |
| 1183 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); | 1183 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); |
| 1184 EXPECT_CALL( | 1184 EXPECT_CALL( |
| 1185 *context, | 1185 *context, |
| 1186 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); | 1186 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); |
| 1187 EXPECT_CALL( | 1187 EXPECT_CALL( |
| 1188 *context, | 1188 *context, |
| 1189 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); | 1189 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); |
| 1190 EXPECT_CALL(*context, | 1190 EXPECT_CALL(*context, |
| 1191 texParameteri(GL_TEXTURE_2D, | 1191 texParameteri(GL_TEXTURE_2D, |
| 1192 GL_TEXTURE_POOL_CHROMIUM, | 1192 GL_TEXTURE_POOL_CHROMIUM, |
| 1193 GL_TEXTURE_POOL_MANAGED_CHROMIUM)); | 1193 GL_TEXTURE_POOL_MANAGED_CHROMIUM)); |
| 1194 resource_provider->CreateForTesting(id); | 1194 resource_provider->CreateForTesting(id); |
| 1195 EXPECT_NE(0u, id); | 1195 EXPECT_NE(0u, id); |
| 1196 | 1196 |
| 1197 Mock::VerifyAndClearExpectations(context); | 1197 Mock::VerifyAndClearExpectations(context); |
| 1198 } | 1198 } |
| 1199 | 1199 |
| 1200 TEST_P(ResourceProviderTest, TextureWrapMode) { |
| 1201 // Sampling is only supported for GL textures. |
| 1202 if (GetParam() != ResourceProvider::GLTexture) |
| 1203 return; |
| 1204 |
| 1205 scoped_ptr<TextureStateTrackingContext> context_owned( |
| 1206 new TextureStateTrackingContext); |
| 1207 TextureStateTrackingContext* context = context_owned.get(); |
| 1208 |
| 1209 FakeOutputSurfaceClient output_surface_client; |
| 1210 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
| 1211 context_owned.PassAs<TestWebGraphicsContext3D>())); |
| 1212 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 1213 |
| 1214 scoped_ptr<ResourceProvider> resource_provider( |
| 1215 ResourceProvider::Create(output_surface.get(), 0)); |
| 1216 |
| 1217 gfx::Size size(1, 1); |
| 1218 WGC3Denum format = GL_RGBA; |
| 1219 int texture_id = 1; |
| 1220 GLenum texture_pool = GL_TEXTURE_POOL_UNMANAGED_CHROMIUM; |
| 1221 |
| 1222 for (int i = 0; i < 2; ++i) { |
| 1223 GLint wrap_mode = i ? GL_CLAMP_TO_EDGE : GL_REPEAT; |
| 1224 // Check that the texture gets created with the right sampler settings. |
| 1225 ResourceProvider::ResourceId id = resource_provider->CreateGLTexture( |
| 1226 size, format, texture_pool, wrap_mode, |
| 1227 ResourceProvider::TextureUsageAny); |
| 1228 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)); |
| 1229 EXPECT_CALL(*context, |
| 1230 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); |
| 1231 EXPECT_CALL(*context, |
| 1232 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); |
| 1233 EXPECT_CALL( |
| 1234 *context, |
| 1235 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_mode)); |
| 1236 EXPECT_CALL( |
| 1237 *context, |
| 1238 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_mode)); |
| 1239 EXPECT_CALL(*context, |
| 1240 texParameteri(GL_TEXTURE_2D, |
| 1241 GL_TEXTURE_POOL_CHROMIUM, |
| 1242 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM)); |
| 1243 resource_provider->CreateForTesting(id); |
| 1244 EXPECT_NE(0u, id); |
| 1245 |
| 1246 Mock::VerifyAndClearExpectations(context); |
| 1247 } |
| 1248 } |
| 1249 |
| 1200 static void EmptyReleaseCallback(unsigned sync_point, bool lost_resource) {} | 1250 static void EmptyReleaseCallback(unsigned sync_point, bool lost_resource) {} |
| 1201 | 1251 |
| 1202 TEST_P(ResourceProviderTest, TextureMailbox_SharedMemory) { | 1252 TEST_P(ResourceProviderTest, TextureMailbox_SharedMemory) { |
| 1203 if (GetParam() != ResourceProvider::Bitmap) | 1253 if (GetParam() != ResourceProvider::Bitmap) |
| 1204 return; | 1254 return; |
| 1205 | 1255 |
| 1206 gfx::Size size(64, 64); | 1256 gfx::Size size(64, 64); |
| 1207 const uint32_t kBadBeef = 0xbadbeef; | 1257 const uint32_t kBadBeef = 0xbadbeef; |
| 1208 scoped_ptr<base::SharedMemory> shared_memory( | 1258 scoped_ptr<base::SharedMemory> shared_memory( |
| 1209 CreateAndFillSharedMemory(size, kBadBeef)); | 1259 CreateAndFillSharedMemory(size, kBadBeef)); |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1438 gfx::Size size(2, 2); | 1488 gfx::Size size(2, 2); |
| 1439 gfx::Vector2d offset(0, 0); | 1489 gfx::Vector2d offset(0, 0); |
| 1440 gfx::Rect rect(0, 0, 2, 2); | 1490 gfx::Rect rect(0, 0, 2, 2); |
| 1441 WGC3Denum format = GL_RGBA; | 1491 WGC3Denum format = GL_RGBA; |
| 1442 ResourceProvider::ResourceId id = 0; | 1492 ResourceProvider::ResourceId id = 0; |
| 1443 uint8_t pixels[16] = { 0 }; | 1493 uint8_t pixels[16] = { 0 }; |
| 1444 int texture_id = 123; | 1494 int texture_id = 123; |
| 1445 | 1495 |
| 1446 // Lazy allocation. Don't allocate when creating the resource. | 1496 // Lazy allocation. Don't allocate when creating the resource. |
| 1447 id = resource_provider->CreateResource( | 1497 id = resource_provider->CreateResource( |
| 1448 size, format, ResourceProvider::TextureUsageAny); | 1498 size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny); |
| 1449 | 1499 |
| 1450 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id)); | 1500 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id)); |
| 1451 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1); | 1501 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1); |
| 1452 resource_provider->CreateForTesting(id); | 1502 resource_provider->CreateForTesting(id); |
| 1453 | 1503 |
| 1454 EXPECT_CALL(*context, deleteTexture(texture_id)).Times(1); | 1504 EXPECT_CALL(*context, deleteTexture(texture_id)).Times(1); |
| 1455 resource_provider->DeleteResource(id); | 1505 resource_provider->DeleteResource(id); |
| 1456 | 1506 |
| 1457 Mock::VerifyAndClearExpectations(context); | 1507 Mock::VerifyAndClearExpectations(context); |
| 1458 | 1508 |
| 1459 // Do allocate when we set the pixels. | 1509 // Do allocate when we set the pixels. |
| 1460 id = resource_provider->CreateResource( | 1510 id = resource_provider->CreateResource( |
| 1461 size, format, ResourceProvider::TextureUsageAny); | 1511 size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny); |
| 1462 | 1512 |
| 1463 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id)); | 1513 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id)); |
| 1464 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(3); | 1514 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(3); |
| 1465 EXPECT_CALL(*context, texImage2D(_, _, _, 2, 2, _, _, _, _)).Times(1); | 1515 EXPECT_CALL(*context, texImage2D(_, _, _, 2, 2, _, _, _, _)).Times(1); |
| 1466 EXPECT_CALL(*context, texSubImage2D(_, _, _, _, 2, 2, _, _, _)).Times(1); | 1516 EXPECT_CALL(*context, texSubImage2D(_, _, _, _, 2, 2, _, _, _)).Times(1); |
| 1467 resource_provider->SetPixels(id, pixels, rect, rect, offset); | 1517 resource_provider->SetPixels(id, pixels, rect, rect, offset); |
| 1468 | 1518 |
| 1469 EXPECT_CALL(*context, deleteTexture(texture_id)).Times(1); | 1519 EXPECT_CALL(*context, deleteTexture(texture_id)).Times(1); |
| 1470 resource_provider->DeleteResource(id); | 1520 resource_provider->DeleteResource(id); |
| 1471 | 1521 |
| 1472 Mock::VerifyAndClearExpectations(context); | 1522 Mock::VerifyAndClearExpectations(context); |
| 1473 | 1523 |
| 1474 // Same for async version. | 1524 // Same for async version. |
| 1475 id = resource_provider->CreateResource( | 1525 id = resource_provider->CreateResource( |
| 1476 size, format, ResourceProvider::TextureUsageAny); | 1526 size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny); |
| 1477 resource_provider->AcquirePixelBuffer(id); | 1527 resource_provider->AcquirePixelBuffer(id); |
| 1478 | 1528 |
| 1479 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id)); | 1529 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id)); |
| 1480 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); | 1530 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); |
| 1481 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) | 1531 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) |
| 1482 .Times(1); | 1532 .Times(1); |
| 1483 resource_provider->BeginSetPixels(id); | 1533 resource_provider->BeginSetPixels(id); |
| 1484 ASSERT_TRUE(resource_provider->DidSetPixelsComplete(id)); | 1534 ASSERT_TRUE(resource_provider->DidSetPixelsComplete(id)); |
| 1485 | 1535 |
| 1486 resource_provider->ReleasePixelBuffer(id); | 1536 resource_provider->ReleasePixelBuffer(id); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1505 | 1555 |
| 1506 gfx::Size size(2, 2); | 1556 gfx::Size size(2, 2); |
| 1507 WGC3Denum format = GL_RGBA; | 1557 WGC3Denum format = GL_RGBA; |
| 1508 ResourceProvider::ResourceId id = 0; | 1558 ResourceProvider::ResourceId id = 0; |
| 1509 int texture_id = 123; | 1559 int texture_id = 123; |
| 1510 | 1560 |
| 1511 scoped_ptr<ResourceProvider> resource_provider( | 1561 scoped_ptr<ResourceProvider> resource_provider( |
| 1512 ResourceProvider::Create(output_surface.get(), 0)); | 1562 ResourceProvider::Create(output_surface.get(), 0)); |
| 1513 | 1563 |
| 1514 id = resource_provider->CreateResource( | 1564 id = resource_provider->CreateResource( |
| 1515 size, format, ResourceProvider::TextureUsageAny); | 1565 size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny); |
| 1516 resource_provider->AcquirePixelBuffer(id); | 1566 resource_provider->AcquirePixelBuffer(id); |
| 1517 | 1567 |
| 1518 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id)); | 1568 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id)); |
| 1519 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); | 1569 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); |
| 1520 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) | 1570 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) |
| 1521 .Times(1); | 1571 .Times(1); |
| 1522 resource_provider->BeginSetPixels(id); | 1572 resource_provider->BeginSetPixels(id); |
| 1523 | 1573 |
| 1524 EXPECT_TRUE(resource_provider->DidSetPixelsComplete(id)); | 1574 EXPECT_TRUE(resource_provider->DidSetPixelsComplete(id)); |
| 1525 | 1575 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1542 | 1592 |
| 1543 gfx::Size size(1, 1); | 1593 gfx::Size size(1, 1); |
| 1544 WGC3Denum format = GL_RGBA; | 1594 WGC3Denum format = GL_RGBA; |
| 1545 ResourceProvider::ResourceId id = 0; | 1595 ResourceProvider::ResourceId id = 0; |
| 1546 const uint32_t kBadBeef = 0xbadbeef; | 1596 const uint32_t kBadBeef = 0xbadbeef; |
| 1547 | 1597 |
| 1548 scoped_ptr<ResourceProvider> resource_provider( | 1598 scoped_ptr<ResourceProvider> resource_provider( |
| 1549 ResourceProvider::Create(output_surface.get(), 0)); | 1599 ResourceProvider::Create(output_surface.get(), 0)); |
| 1550 | 1600 |
| 1551 id = resource_provider->CreateResource( | 1601 id = resource_provider->CreateResource( |
| 1552 size, format, ResourceProvider::TextureUsageAny); | 1602 size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny); |
| 1553 resource_provider->AcquirePixelBuffer(id); | 1603 resource_provider->AcquirePixelBuffer(id); |
| 1554 | 1604 |
| 1555 void* data = resource_provider->MapPixelBuffer(id); | 1605 void* data = resource_provider->MapPixelBuffer(id); |
| 1556 ASSERT_TRUE(!!data); | 1606 ASSERT_TRUE(!!data); |
| 1557 memcpy(data, &kBadBeef, sizeof(kBadBeef)); | 1607 memcpy(data, &kBadBeef, sizeof(kBadBeef)); |
| 1558 resource_provider->UnmapPixelBuffer(id); | 1608 resource_provider->UnmapPixelBuffer(id); |
| 1559 | 1609 |
| 1560 resource_provider->BeginSetPixels(id); | 1610 resource_provider->BeginSetPixels(id); |
| 1561 EXPECT_TRUE(resource_provider->DidSetPixelsComplete(id)); | 1611 EXPECT_TRUE(resource_provider->DidSetPixelsComplete(id)); |
| 1562 | 1612 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1588 | 1638 |
| 1589 gfx::Size size(2, 2); | 1639 gfx::Size size(2, 2); |
| 1590 WGC3Denum format = GL_RGBA; | 1640 WGC3Denum format = GL_RGBA; |
| 1591 ResourceProvider::ResourceId id = 0; | 1641 ResourceProvider::ResourceId id = 0; |
| 1592 int texture_id = 123; | 1642 int texture_id = 123; |
| 1593 | 1643 |
| 1594 scoped_ptr<ResourceProvider> resource_provider( | 1644 scoped_ptr<ResourceProvider> resource_provider( |
| 1595 ResourceProvider::Create(output_surface.get(), 0)); | 1645 ResourceProvider::Create(output_surface.get(), 0)); |
| 1596 | 1646 |
| 1597 id = resource_provider->CreateResource( | 1647 id = resource_provider->CreateResource( |
| 1598 size, format, ResourceProvider::TextureUsageAny); | 1648 size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny); |
| 1599 resource_provider->AcquirePixelBuffer(id); | 1649 resource_provider->AcquirePixelBuffer(id); |
| 1600 | 1650 |
| 1601 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id)); | 1651 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id)); |
| 1602 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); | 1652 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); |
| 1603 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) | 1653 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) |
| 1604 .Times(1); | 1654 .Times(1); |
| 1605 resource_provider->BeginSetPixels(id); | 1655 resource_provider->BeginSetPixels(id); |
| 1606 | 1656 |
| 1607 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1); | 1657 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1); |
| 1608 EXPECT_CALL(*context, waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)).Times(1); | 1658 EXPECT_CALL(*context, waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)).Times(1); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1631 WGC3Denum format = GL_RGBA; | 1681 WGC3Denum format = GL_RGBA; |
| 1632 ResourceProvider::ResourceId id = 0; | 1682 ResourceProvider::ResourceId id = 0; |
| 1633 int texture_id = 123; | 1683 int texture_id = 123; |
| 1634 | 1684 |
| 1635 scoped_ptr<ResourceProvider> resource_provider( | 1685 scoped_ptr<ResourceProvider> resource_provider( |
| 1636 ResourceProvider::Create(output_surface.get(), 0)); | 1686 ResourceProvider::Create(output_surface.get(), 0)); |
| 1637 | 1687 |
| 1638 EXPECT_CALL(*context, createTexture()).WillRepeatedly(Return(texture_id)); | 1688 EXPECT_CALL(*context, createTexture()).WillRepeatedly(Return(texture_id)); |
| 1639 | 1689 |
| 1640 id = resource_provider->CreateResource( | 1690 id = resource_provider->CreateResource( |
| 1641 size, format, ResourceProvider::TextureUsageAny); | 1691 size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny); |
| 1642 context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, | 1692 context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, |
| 1643 GL_INNOCENT_CONTEXT_RESET_ARB); | 1693 GL_INNOCENT_CONTEXT_RESET_ARB); |
| 1644 resource_provider->AcquirePixelBuffer(id); | 1694 resource_provider->AcquirePixelBuffer(id); |
| 1645 uint8_t* buffer = resource_provider->MapPixelBuffer(id); | 1695 uint8_t* buffer = resource_provider->MapPixelBuffer(id); |
| 1646 EXPECT_TRUE(buffer == NULL); | 1696 EXPECT_TRUE(buffer == NULL); |
| 1647 resource_provider->UnmapPixelBuffer(id); | 1697 resource_provider->UnmapPixelBuffer(id); |
| 1648 resource_provider->ReleasePixelBuffer(id); | 1698 resource_provider->ReleasePixelBuffer(id); |
| 1649 Mock::VerifyAndClearExpectations(context); | 1699 Mock::VerifyAndClearExpectations(context); |
| 1650 } | 1700 } |
| 1651 | 1701 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1667 gfx::Size size(kWidth, kHeight); | 1717 gfx::Size size(kWidth, kHeight); |
| 1668 WGC3Denum format = GL_RGBA; | 1718 WGC3Denum format = GL_RGBA; |
| 1669 ResourceProvider::ResourceId id = 0; | 1719 ResourceProvider::ResourceId id = 0; |
| 1670 const unsigned kTextureId = 123u; | 1720 const unsigned kTextureId = 123u; |
| 1671 const unsigned kImageId = 234u; | 1721 const unsigned kImageId = 234u; |
| 1672 | 1722 |
| 1673 scoped_ptr<ResourceProvider> resource_provider( | 1723 scoped_ptr<ResourceProvider> resource_provider( |
| 1674 ResourceProvider::Create(output_surface.get(), 0)); | 1724 ResourceProvider::Create(output_surface.get(), 0)); |
| 1675 | 1725 |
| 1676 id = resource_provider->CreateResource( | 1726 id = resource_provider->CreateResource( |
| 1677 size, format, ResourceProvider::TextureUsageAny); | 1727 size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny); |
| 1678 EXPECT_CALL(*context, createImageCHROMIUM(kWidth, kHeight, GL_RGBA8_OES)) | 1728 EXPECT_CALL(*context, createImageCHROMIUM(kWidth, kHeight, GL_RGBA8_OES)) |
| 1679 .WillOnce(Return(kImageId)) | 1729 .WillOnce(Return(kImageId)) |
| 1680 .RetiresOnSaturation(); | 1730 .RetiresOnSaturation(); |
| 1681 resource_provider->AcquireImage(id); | 1731 resource_provider->AcquireImage(id); |
| 1682 | 1732 |
| 1683 void* dummy_mapped_buffer_address = NULL; | 1733 void* dummy_mapped_buffer_address = NULL; |
| 1684 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId, GL_READ_WRITE)) | 1734 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId, GL_READ_WRITE)) |
| 1685 .WillOnce(Return(dummy_mapped_buffer_address)) | 1735 .WillOnce(Return(dummy_mapped_buffer_address)) |
| 1686 .RetiresOnSaturation(); | 1736 .RetiresOnSaturation(); |
| 1687 resource_provider->MapImage(id); | 1737 resource_provider->MapImage(id); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1738 | 1788 |
| 1739 gfx::Size size(1, 1); | 1789 gfx::Size size(1, 1); |
| 1740 WGC3Denum format = GL_RGBA; | 1790 WGC3Denum format = GL_RGBA; |
| 1741 ResourceProvider::ResourceId id = 0; | 1791 ResourceProvider::ResourceId id = 0; |
| 1742 const uint32_t kBadBeef = 0xbadbeef; | 1792 const uint32_t kBadBeef = 0xbadbeef; |
| 1743 | 1793 |
| 1744 scoped_ptr<ResourceProvider> resource_provider( | 1794 scoped_ptr<ResourceProvider> resource_provider( |
| 1745 ResourceProvider::Create(output_surface.get(), 0)); | 1795 ResourceProvider::Create(output_surface.get(), 0)); |
| 1746 | 1796 |
| 1747 id = resource_provider->CreateResource( | 1797 id = resource_provider->CreateResource( |
| 1748 size, format, ResourceProvider::TextureUsageAny); | 1798 size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny); |
| 1749 resource_provider->AcquireImage(id); | 1799 resource_provider->AcquireImage(id); |
| 1750 | 1800 |
| 1751 const int kStride = 0; | 1801 const int kStride = 0; |
| 1752 int stride = resource_provider->GetImageStride(id); | 1802 int stride = resource_provider->GetImageStride(id); |
| 1753 EXPECT_EQ(kStride, stride); | 1803 EXPECT_EQ(kStride, stride); |
| 1754 | 1804 |
| 1755 void* data = resource_provider->MapImage(id); | 1805 void* data = resource_provider->MapImage(id); |
| 1756 ASSERT_TRUE(!!data); | 1806 ASSERT_TRUE(!!data); |
| 1757 memcpy(data, &kBadBeef, sizeof(kBadBeef)); | 1807 memcpy(data, &kBadBeef, sizeof(kBadBeef)); |
| 1758 resource_provider->UnmapImage(id); | 1808 resource_provider->UnmapImage(id); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1810 output_surface.get()); | 1860 output_surface.get()); |
| 1811 } | 1861 } |
| 1812 | 1862 |
| 1813 INSTANTIATE_TEST_CASE_P( | 1863 INSTANTIATE_TEST_CASE_P( |
| 1814 ResourceProviderTests, | 1864 ResourceProviderTests, |
| 1815 ResourceProviderTest, | 1865 ResourceProviderTest, |
| 1816 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap)); | 1866 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap)); |
| 1817 | 1867 |
| 1818 } // namespace | 1868 } // namespace |
| 1819 } // namespace cc | 1869 } // namespace cc |
| OLD | NEW |