| 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/logging.h" | 10 #include "base/logging.h" |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 }; | 330 }; |
| 331 | 331 |
| 332 class ResourceProviderTest | 332 class ResourceProviderTest |
| 333 : public testing::TestWithParam<ResourceProvider::ResourceType> { | 333 : public testing::TestWithParam<ResourceProvider::ResourceType> { |
| 334 public: | 334 public: |
| 335 ResourceProviderTest() | 335 ResourceProviderTest() |
| 336 : shared_data_(ContextSharedData::Create()), | 336 : shared_data_(ContextSharedData::Create()), |
| 337 output_surface_(FakeOutputSurface::Create3d( | 337 output_surface_(FakeOutputSurface::Create3d( |
| 338 ResourceProviderContext::Create(shared_data_.get()) | 338 ResourceProviderContext::Create(shared_data_.get()) |
| 339 .PassAs<WebKit::WebGraphicsContext3D>())), | 339 .PassAs<WebKit::WebGraphicsContext3D>())), |
| 340 resource_provider_(ResourceProvider::Create(output_surface_.get())) { | 340 resource_provider_(ResourceProvider::Create(output_surface_.get(), 0)) { |
| 341 resource_provider_->set_default_resource_type(GetParam()); | 341 resource_provider_->set_default_resource_type(GetParam()); |
| 342 } | 342 } |
| 343 | 343 |
| 344 ResourceProviderContext* context() { | 344 ResourceProviderContext* context() { |
| 345 return static_cast<ResourceProviderContext*>(output_surface_->context3d()); | 345 return static_cast<ResourceProviderContext*>(output_surface_->context3d()); |
| 346 } | 346 } |
| 347 | 347 |
| 348 void GetResourcePixels(ResourceProvider::ResourceId id, | 348 void GetResourcePixels(ResourceProvider::ResourceId id, |
| 349 gfx::Size size, | 349 gfx::Size size, |
| 350 WGC3Denum format, | 350 WGC3Denum format, |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 | 480 |
| 481 TEST_P(ResourceProviderTest, TransferResources) { | 481 TEST_P(ResourceProviderTest, TransferResources) { |
| 482 // Resource transfer is only supported with GL textures for now. | 482 // Resource transfer is only supported with GL textures for now. |
| 483 if (GetParam() != ResourceProvider::GLTexture) | 483 if (GetParam() != ResourceProvider::GLTexture) |
| 484 return; | 484 return; |
| 485 | 485 |
| 486 scoped_ptr<OutputSurface> child_output_surface(FakeOutputSurface::Create3d( | 486 scoped_ptr<OutputSurface> child_output_surface(FakeOutputSurface::Create3d( |
| 487 ResourceProviderContext::Create(shared_data_.get()) | 487 ResourceProviderContext::Create(shared_data_.get()) |
| 488 .PassAs<WebKit::WebGraphicsContext3D>())); | 488 .PassAs<WebKit::WebGraphicsContext3D>())); |
| 489 scoped_ptr<ResourceProvider> child_resource_provider( | 489 scoped_ptr<ResourceProvider> child_resource_provider( |
| 490 ResourceProvider::Create(child_output_surface.get())); | 490 ResourceProvider::Create(child_output_surface.get(), 0)); |
| 491 | 491 |
| 492 gfx::Size size(1, 1); | 492 gfx::Size size(1, 1); |
| 493 WGC3Denum format = GL_RGBA; | 493 WGC3Denum format = GL_RGBA; |
| 494 size_t pixel_size = TextureSize(size, format); | 494 size_t pixel_size = TextureSize(size, format); |
| 495 ASSERT_EQ(4U, pixel_size); | 495 ASSERT_EQ(4U, pixel_size); |
| 496 | 496 |
| 497 ResourceProvider::ResourceId id1 = child_resource_provider->CreateResource( | 497 ResourceProvider::ResourceId id1 = child_resource_provider->CreateResource( |
| 498 size, format, ResourceProvider::TextureUsageAny); | 498 size, format, ResourceProvider::TextureUsageAny); |
| 499 uint8_t data1[4] = { 1, 2, 3, 4 }; | 499 uint8_t data1[4] = { 1, 2, 3, 4 }; |
| 500 gfx::Rect rect(size); | 500 gfx::Rect rect(size); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 | 603 |
| 604 TEST_P(ResourceProviderTest, DeleteTransferredResources) { | 604 TEST_P(ResourceProviderTest, DeleteTransferredResources) { |
| 605 // Resource transfer is only supported with GL textures for now. | 605 // Resource transfer is only supported with GL textures for now. |
| 606 if (GetParam() != ResourceProvider::GLTexture) | 606 if (GetParam() != ResourceProvider::GLTexture) |
| 607 return; | 607 return; |
| 608 | 608 |
| 609 scoped_ptr<OutputSurface> child_output_surface(FakeOutputSurface::Create3d( | 609 scoped_ptr<OutputSurface> child_output_surface(FakeOutputSurface::Create3d( |
| 610 ResourceProviderContext::Create(shared_data_.get()) | 610 ResourceProviderContext::Create(shared_data_.get()) |
| 611 .PassAs<WebKit::WebGraphicsContext3D>())); | 611 .PassAs<WebKit::WebGraphicsContext3D>())); |
| 612 scoped_ptr<ResourceProvider> child_resource_provider( | 612 scoped_ptr<ResourceProvider> child_resource_provider( |
| 613 ResourceProvider::Create(child_output_surface.get())); | 613 ResourceProvider::Create(child_output_surface.get(), 0)); |
| 614 | 614 |
| 615 gfx::Size size(1, 1); | 615 gfx::Size size(1, 1); |
| 616 WGC3Denum format = GL_RGBA; | 616 WGC3Denum format = GL_RGBA; |
| 617 size_t pixel_size = TextureSize(size, format); | 617 size_t pixel_size = TextureSize(size, format); |
| 618 ASSERT_EQ(4U, pixel_size); | 618 ASSERT_EQ(4U, pixel_size); |
| 619 | 619 |
| 620 ResourceProvider::ResourceId id = child_resource_provider->CreateResource( | 620 ResourceProvider::ResourceId id = child_resource_provider->CreateResource( |
| 621 size, format, ResourceProvider::TextureUsageAny); | 621 size, format, ResourceProvider::TextureUsageAny); |
| 622 uint8_t data[4] = { 1, 2, 3, 4 }; | 622 uint8_t data[4] = { 1, 2, 3, 4 }; |
| 623 gfx::Rect rect(size); | 623 gfx::Rect rect(size); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 | 660 |
| 661 TEST_P(ResourceProviderTest, TextureFilters) { | 661 TEST_P(ResourceProviderTest, TextureFilters) { |
| 662 // Resource transfer is only supported with GL textures for now. | 662 // Resource transfer is only supported with GL textures for now. |
| 663 if (GetParam() != ResourceProvider::GLTexture) | 663 if (GetParam() != ResourceProvider::GLTexture) |
| 664 return; | 664 return; |
| 665 | 665 |
| 666 scoped_ptr<OutputSurface> child_output_surface(FakeOutputSurface::Create3d( | 666 scoped_ptr<OutputSurface> child_output_surface(FakeOutputSurface::Create3d( |
| 667 ResourceProviderContext::Create(shared_data_.get()) | 667 ResourceProviderContext::Create(shared_data_.get()) |
| 668 .PassAs<WebKit::WebGraphicsContext3D>())); | 668 .PassAs<WebKit::WebGraphicsContext3D>())); |
| 669 scoped_ptr<ResourceProvider> child_resource_provider( | 669 scoped_ptr<ResourceProvider> child_resource_provider( |
| 670 ResourceProvider::Create(child_output_surface.get())); | 670 ResourceProvider::Create(child_output_surface.get(), 0)); |
| 671 | 671 |
| 672 gfx::Size size(1, 1); | 672 gfx::Size size(1, 1); |
| 673 WGC3Denum format = GL_RGBA; | 673 WGC3Denum format = GL_RGBA; |
| 674 size_t pixel_size = TextureSize(size, format); | 674 size_t pixel_size = TextureSize(size, format); |
| 675 ASSERT_EQ(4U, pixel_size); | 675 ASSERT_EQ(4U, pixel_size); |
| 676 | 676 |
| 677 ResourceProvider::ResourceId id = child_resource_provider->CreateResource( | 677 ResourceProvider::ResourceId id = child_resource_provider->CreateResource( |
| 678 size, format, ResourceProvider::TextureUsageAny); | 678 size, format, ResourceProvider::TextureUsageAny); |
| 679 uint8_t data[4] = { 1, 2, 3, 4 }; | 679 uint8_t data[4] = { 1, 2, 3, 4 }; |
| 680 gfx::Rect rect(size); | 680 gfx::Rect rect(size); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 851 // Sampling is only supported for GL textures. | 851 // Sampling is only supported for GL textures. |
| 852 if (GetParam() != ResourceProvider::GLTexture) | 852 if (GetParam() != ResourceProvider::GLTexture) |
| 853 return; | 853 return; |
| 854 | 854 |
| 855 scoped_ptr<OutputSurface> output_surface( | 855 scoped_ptr<OutputSurface> output_surface( |
| 856 FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>( | 856 FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>( |
| 857 new TextureStateTrackingContext))); | 857 new TextureStateTrackingContext))); |
| 858 TextureStateTrackingContext* context = | 858 TextureStateTrackingContext* context = |
| 859 static_cast<TextureStateTrackingContext*>(output_surface->context3d()); | 859 static_cast<TextureStateTrackingContext*>(output_surface->context3d()); |
| 860 scoped_ptr<ResourceProvider> resource_provider( | 860 scoped_ptr<ResourceProvider> resource_provider( |
| 861 ResourceProvider::Create(output_surface.get())); | 861 ResourceProvider::Create(output_surface.get(), 0)); |
| 862 | 862 |
| 863 gfx::Size size(1, 1); | 863 gfx::Size size(1, 1); |
| 864 WGC3Denum format = GL_RGBA; | 864 WGC3Denum format = GL_RGBA; |
| 865 int texture_id = 1; | 865 int texture_id = 1; |
| 866 | 866 |
| 867 // Check that the texture gets created with the right sampler settings. | 867 // Check that the texture gets created with the right sampler settings. |
| 868 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)) | 868 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)) |
| 869 .Times(2); // Once to create and once to allocate. | 869 .Times(2); // Once to create and once to allocate. |
| 870 EXPECT_CALL(*context, | 870 EXPECT_CALL(*context, |
| 871 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); | 871 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 924 // Sampling is only supported for GL textures. | 924 // Sampling is only supported for GL textures. |
| 925 if (GetParam() != ResourceProvider::GLTexture) | 925 if (GetParam() != ResourceProvider::GLTexture) |
| 926 return; | 926 return; |
| 927 | 927 |
| 928 scoped_ptr<OutputSurface> output_surface( | 928 scoped_ptr<OutputSurface> output_surface( |
| 929 FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>( | 929 FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>( |
| 930 new TextureStateTrackingContext))); | 930 new TextureStateTrackingContext))); |
| 931 TextureStateTrackingContext* context = | 931 TextureStateTrackingContext* context = |
| 932 static_cast<TextureStateTrackingContext*>(output_surface->context3d()); | 932 static_cast<TextureStateTrackingContext*>(output_surface->context3d()); |
| 933 scoped_ptr<ResourceProvider> resource_provider( | 933 scoped_ptr<ResourceProvider> resource_provider( |
| 934 ResourceProvider::Create(output_surface.get())); | 934 ResourceProvider::Create(output_surface.get(), 0)); |
| 935 | 935 |
| 936 gfx::Size size(1, 1); | 936 gfx::Size size(1, 1); |
| 937 WGC3Denum format = GL_RGBA; | 937 WGC3Denum format = GL_RGBA; |
| 938 int texture_id = 1; | 938 int texture_id = 1; |
| 939 | 939 |
| 940 // Check that the texture gets created with the right sampler settings. | 940 // Check that the texture gets created with the right sampler settings. |
| 941 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)); | 941 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)); |
| 942 EXPECT_CALL(*context, | 942 EXPECT_CALL(*context, |
| 943 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); | 943 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); |
| 944 EXPECT_CALL(*context, | 944 EXPECT_CALL(*context, |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1022 gfx::Vector2d offset(0, 0); | 1022 gfx::Vector2d offset(0, 0); |
| 1023 gfx::Rect rect(0, 0, 2, 2); | 1023 gfx::Rect rect(0, 0, 2, 2); |
| 1024 WGC3Denum format = GL_RGBA; | 1024 WGC3Denum format = GL_RGBA; |
| 1025 ResourceProvider::ResourceId id = 0; | 1025 ResourceProvider::ResourceId id = 0; |
| 1026 uint8_t pixels[16] = { 0 }; | 1026 uint8_t pixels[16] = { 0 }; |
| 1027 int texture_id = 123; | 1027 int texture_id = 123; |
| 1028 | 1028 |
| 1029 AllocationTrackingContext3D* context = | 1029 AllocationTrackingContext3D* context = |
| 1030 static_cast<AllocationTrackingContext3D*>(output_surface->context3d()); | 1030 static_cast<AllocationTrackingContext3D*>(output_surface->context3d()); |
| 1031 scoped_ptr<ResourceProvider> resource_provider( | 1031 scoped_ptr<ResourceProvider> resource_provider( |
| 1032 ResourceProvider::Create(output_surface.get())); | 1032 ResourceProvider::Create(output_surface.get(), 0)); |
| 1033 | 1033 |
| 1034 // Lazy allocation. Don't allocate when creating the resource. | 1034 // Lazy allocation. Don't allocate when creating the resource. |
| 1035 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id)); | 1035 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id)); |
| 1036 EXPECT_CALL(*context, deleteTexture(texture_id)).Times(1); | 1036 EXPECT_CALL(*context, deleteTexture(texture_id)).Times(1); |
| 1037 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1); | 1037 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1); |
| 1038 EXPECT_CALL(*context, texImage2D(_, _, _, _, _, _, _, _, _)).Times(0); | 1038 EXPECT_CALL(*context, texImage2D(_, _, _, _, _, _, _, _, _)).Times(0); |
| 1039 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, _, _, _, _, _, _)) | 1039 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, _, _, _, _, _, _)) |
| 1040 .Times(0); | 1040 .Times(0); |
| 1041 id = resource_provider->CreateResource( | 1041 id = resource_provider->CreateResource( |
| 1042 size, format, ResourceProvider::TextureUsageAny); | 1042 size, format, ResourceProvider::TextureUsageAny); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1095 FakeOutputSurface::Create3d(mock_context.Pass())); | 1095 FakeOutputSurface::Create3d(mock_context.Pass())); |
| 1096 | 1096 |
| 1097 gfx::Size size(2, 2); | 1097 gfx::Size size(2, 2); |
| 1098 WGC3Denum format = GL_RGBA; | 1098 WGC3Denum format = GL_RGBA; |
| 1099 ResourceProvider::ResourceId id = 0; | 1099 ResourceProvider::ResourceId id = 0; |
| 1100 int texture_id = 123; | 1100 int texture_id = 123; |
| 1101 | 1101 |
| 1102 AllocationTrackingContext3D* context = | 1102 AllocationTrackingContext3D* context = |
| 1103 static_cast<AllocationTrackingContext3D*>(output_surface->context3d()); | 1103 static_cast<AllocationTrackingContext3D*>(output_surface->context3d()); |
| 1104 scoped_ptr<ResourceProvider> resource_provider( | 1104 scoped_ptr<ResourceProvider> resource_provider( |
| 1105 ResourceProvider::Create(output_surface.get())); | 1105 ResourceProvider::Create(output_surface.get(), 0)); |
| 1106 | 1106 |
| 1107 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id)); | 1107 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id)); |
| 1108 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(3); | 1108 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(3); |
| 1109 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) | 1109 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) |
| 1110 .Times(1); | 1110 .Times(1); |
| 1111 EXPECT_CALL(*context, waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)).Times(1); | 1111 EXPECT_CALL(*context, waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)).Times(1); |
| 1112 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, 0)).Times(1); | 1112 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, 0)).Times(1); |
| 1113 id = resource_provider->CreateResource( | 1113 id = resource_provider->CreateResource( |
| 1114 size, format, ResourceProvider::TextureUsageAny); | 1114 size, format, ResourceProvider::TextureUsageAny); |
| 1115 resource_provider->AcquirePixelBuffer(id); | 1115 resource_provider->AcquirePixelBuffer(id); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1130 FakeOutputSurface::Create3d(mock_context.Pass())); | 1130 FakeOutputSurface::Create3d(mock_context.Pass())); |
| 1131 | 1131 |
| 1132 gfx::Size size(2, 2); | 1132 gfx::Size size(2, 2); |
| 1133 WGC3Denum format = GL_RGBA; | 1133 WGC3Denum format = GL_RGBA; |
| 1134 ResourceProvider::ResourceId id = 0; | 1134 ResourceProvider::ResourceId id = 0; |
| 1135 int texture_id = 123; | 1135 int texture_id = 123; |
| 1136 | 1136 |
| 1137 AllocationTrackingContext3D* context = | 1137 AllocationTrackingContext3D* context = |
| 1138 static_cast<AllocationTrackingContext3D*>(output_surface->context3d()); | 1138 static_cast<AllocationTrackingContext3D*>(output_surface->context3d()); |
| 1139 scoped_ptr<ResourceProvider> resource_provider( | 1139 scoped_ptr<ResourceProvider> resource_provider( |
| 1140 ResourceProvider::Create(output_surface.get())); | 1140 ResourceProvider::Create(output_surface.get(), 0)); |
| 1141 | 1141 |
| 1142 EXPECT_CALL(*context, createTexture()).WillRepeatedly(Return(texture_id)); | 1142 EXPECT_CALL(*context, createTexture()).WillRepeatedly(Return(texture_id)); |
| 1143 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(4); | 1143 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(4); |
| 1144 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) | 1144 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) |
| 1145 .Times(1); | 1145 .Times(1); |
| 1146 EXPECT_CALL(*context, waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)).Times(1); | 1146 EXPECT_CALL(*context, waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)).Times(1); |
| 1147 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, 0)).Times(1); | 1147 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, 0)).Times(1); |
| 1148 EXPECT_CALL(*context, deleteTexture(_)).Times(1); | 1148 EXPECT_CALL(*context, deleteTexture(_)).Times(1); |
| 1149 id = resource_provider->CreateResource( | 1149 id = resource_provider->CreateResource( |
| 1150 size, format, ResourceProvider::TextureUsageAny); | 1150 size, format, ResourceProvider::TextureUsageAny); |
| 1151 resource_provider->AcquirePixelBuffer(id); | 1151 resource_provider->AcquirePixelBuffer(id); |
| 1152 resource_provider->BeginSetPixels(id); | 1152 resource_provider->BeginSetPixels(id); |
| 1153 resource_provider->ForceSetPixelsToComplete(id); | 1153 resource_provider->ForceSetPixelsToComplete(id); |
| 1154 resource_provider->AbortSetPixels(id); | 1154 resource_provider->AbortSetPixels(id); |
| 1155 resource_provider->ReleasePixelBuffer(id); | 1155 resource_provider->ReleasePixelBuffer(id); |
| 1156 Mock::VerifyAndClearExpectations(context); | 1156 Mock::VerifyAndClearExpectations(context); |
| 1157 } | 1157 } |
| 1158 | 1158 |
| 1159 INSTANTIATE_TEST_CASE_P( | 1159 INSTANTIATE_TEST_CASE_P( |
| 1160 ResourceProviderTests, | 1160 ResourceProviderTests, |
| 1161 ResourceProviderTest, | 1161 ResourceProviderTest, |
| 1162 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap)); | 1162 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap)); |
| 1163 | 1163 |
| 1164 } // namespace | 1164 } // namespace |
| 1165 } // namespace cc | 1165 } // namespace cc |
| OLD | NEW |