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 856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
867 | 867 |
868 EXPECT_EQ(0u, release_sync_point); | 868 EXPECT_EQ(0u, release_sync_point); |
869 EXPECT_FALSE(lost_resource); | 869 EXPECT_FALSE(lost_resource); |
870 | 870 |
871 resource_provider_.reset(); | 871 resource_provider_.reset(); |
872 | 872 |
873 EXPECT_LE(sync_point, release_sync_point); | 873 EXPECT_LE(sync_point, release_sync_point); |
874 EXPECT_FALSE(lost_resource); | 874 EXPECT_FALSE(lost_resource); |
875 } | 875 } |
876 | 876 |
| 877 static scoped_ptr<base::SharedMemory> CreateAndFillSharedMemory( |
| 878 gfx::Size size, uint32_t value) { |
| 879 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory); |
| 880 CHECK(shared_memory->CreateAndMapAnonymous(4 * size.GetArea())); |
| 881 uint32_t* pixels = reinterpret_cast<uint32_t*>(shared_memory->memory()); |
| 882 CHECK(pixels); |
| 883 std::fill_n(pixels, size.GetArea(), value); |
| 884 return shared_memory.Pass(); |
| 885 } |
| 886 |
| 887 static void ReleaseSharedMemoryCallback( |
| 888 bool* release_called, |
| 889 unsigned sync_point, bool lost_resource) { |
| 890 *release_called = true; |
| 891 } |
| 892 |
| 893 TEST_P(ResourceProviderTest, ShutdownSharedMemory) { |
| 894 if (GetParam() != ResourceProvider::Bitmap) |
| 895 return; |
| 896 |
| 897 gfx::Size size(64, 64); |
| 898 scoped_ptr<base::SharedMemory> shared_memory( |
| 899 CreateAndFillSharedMemory(size, 0)); |
| 900 |
| 901 bool release_called = false; |
| 902 TextureMailbox::ReleaseCallback callback = |
| 903 base::Bind(ReleaseSharedMemoryCallback, &release_called); |
| 904 resource_provider_->CreateResourceFromTextureMailbox( |
| 905 TextureMailbox(shared_memory.get(), size, callback)); |
| 906 |
| 907 resource_provider_.reset(); |
| 908 |
| 909 EXPECT_TRUE(release_called); |
| 910 } |
| 911 |
877 TEST_P(ResourceProviderTest, ShutdownWithExportedResource) { | 912 TEST_P(ResourceProviderTest, ShutdownWithExportedResource) { |
878 // TextureMailbox callbacks only exist for GL textures for now. | 913 // TextureMailbox callbacks only exist for GL textures for now. |
879 if (GetParam() != ResourceProvider::GLTexture) | 914 if (GetParam() != ResourceProvider::GLTexture) |
880 return; | 915 return; |
881 unsigned texture = context()->createTexture(); | 916 unsigned texture = context()->createTexture(); |
882 context()->bindTexture(GL_TEXTURE_2D, texture); | 917 context()->bindTexture(GL_TEXTURE_2D, texture); |
883 gpu::Mailbox mailbox; | 918 gpu::Mailbox mailbox; |
884 context()->genMailboxCHROMIUM(mailbox.name); | 919 context()->genMailboxCHROMIUM(mailbox.name); |
885 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 920 context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
886 unsigned sync_point = context()->insertSyncPoint(); | 921 unsigned sync_point = context()->insertSyncPoint(); |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1065 GL_TEXTURE_POOL_MANAGED_CHROMIUM)); | 1100 GL_TEXTURE_POOL_MANAGED_CHROMIUM)); |
1066 ResourceProvider::ResourceId id = resource_provider->CreateManagedResource( | 1101 ResourceProvider::ResourceId id = resource_provider->CreateManagedResource( |
1067 size, format, ResourceProvider::TextureUsageAny); | 1102 size, format, ResourceProvider::TextureUsageAny); |
1068 EXPECT_NE(0u, id); | 1103 EXPECT_NE(0u, id); |
1069 | 1104 |
1070 Mock::VerifyAndClearExpectations(context); | 1105 Mock::VerifyAndClearExpectations(context); |
1071 } | 1106 } |
1072 | 1107 |
1073 static void EmptyReleaseCallback(unsigned sync_point, bool lost_resource) {} | 1108 static void EmptyReleaseCallback(unsigned sync_point, bool lost_resource) {} |
1074 | 1109 |
| 1110 TEST_P(ResourceProviderTest, TextureMailbox_SharedMemory) { |
| 1111 if (GetParam() != ResourceProvider::Bitmap) |
| 1112 return; |
| 1113 |
| 1114 gfx::Size size(64, 64); |
| 1115 const uint32_t kBadBeef = 0xbadbeef; |
| 1116 scoped_ptr<base::SharedMemory> shared_memory( |
| 1117 CreateAndFillSharedMemory(size, kBadBeef)); |
| 1118 |
| 1119 scoped_ptr<OutputSurface> output_surface( |
| 1120 FakeOutputSurface::CreateSoftware(make_scoped_ptr( |
| 1121 new SoftwareOutputDevice))); |
| 1122 scoped_ptr<ResourceProvider> resource_provider( |
| 1123 ResourceProvider::Create(output_surface.get(), 0)); |
| 1124 |
| 1125 TextureMailbox::ReleaseCallback callback = base::Bind(&EmptyReleaseCallback); |
| 1126 TextureMailbox mailbox(shared_memory.get(), size, callback); |
| 1127 |
| 1128 ResourceProvider::ResourceId id = |
| 1129 resource_provider->CreateResourceFromTextureMailbox(mailbox); |
| 1130 EXPECT_NE(0u, id); |
| 1131 |
| 1132 { |
| 1133 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(), id); |
| 1134 const SkBitmap* sk_bitmap = lock.sk_bitmap(); |
| 1135 EXPECT_EQ(sk_bitmap->width(), size.width()); |
| 1136 EXPECT_EQ(sk_bitmap->height(), size.height()); |
| 1137 EXPECT_EQ(*sk_bitmap->getAddr32(16, 16), kBadBeef); |
| 1138 } |
| 1139 } |
| 1140 |
1075 TEST_P(ResourceProviderTest, TextureMailbox_GLTexture2D) { | 1141 TEST_P(ResourceProviderTest, TextureMailbox_GLTexture2D) { |
1076 // Mailboxing is only supported for GL textures. | 1142 // Mailboxing is only supported for GL textures. |
1077 if (GetParam() != ResourceProvider::GLTexture) | 1143 if (GetParam() != ResourceProvider::GLTexture) |
1078 return; | 1144 return; |
1079 | 1145 |
1080 scoped_ptr<OutputSurface> output_surface( | 1146 scoped_ptr<OutputSurface> output_surface( |
1081 FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>( | 1147 FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>( |
1082 new TextureStateTrackingContext))); | 1148 new TextureStateTrackingContext))); |
1083 TextureStateTrackingContext* context = | 1149 TextureStateTrackingContext* context = |
1084 static_cast<TextureStateTrackingContext*>(output_surface->context3d()); | 1150 static_cast<TextureStateTrackingContext*>(output_surface->context3d()); |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1502 .RetiresOnSaturation(); | 1568 .RetiresOnSaturation(); |
1503 } | 1569 } |
1504 | 1570 |
1505 INSTANTIATE_TEST_CASE_P( | 1571 INSTANTIATE_TEST_CASE_P( |
1506 ResourceProviderTests, | 1572 ResourceProviderTests, |
1507 ResourceProviderTest, | 1573 ResourceProviderTest, |
1508 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap)); | 1574 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap)); |
1509 | 1575 |
1510 } // namespace | 1576 } // namespace |
1511 } // namespace cc | 1577 } // namespace cc |
OLD | NEW |