| 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 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 const WGC3Dbyte* mailbox)); | 92 const WGC3Dbyte* mailbox)); |
| 93 MOCK_METHOD2(consumeTextureCHROMIUM, void(WGC3Denum target, | 93 MOCK_METHOD2(consumeTextureCHROMIUM, void(WGC3Denum target, |
| 94 const WGC3Dbyte* mailbox)); | 94 const WGC3Dbyte* mailbox)); |
| 95 | 95 |
| 96 // Force all textures to be consecutive numbers starting at "1", | 96 // Force all textures to be consecutive numbers starting at "1", |
| 97 // so we easily can test for them. | 97 // so we easily can test for them. |
| 98 virtual WebKit::WebGLId NextTextureId() OVERRIDE { | 98 virtual WebKit::WebGLId NextTextureId() OVERRIDE { |
| 99 base::AutoLock lock(namespace_->lock); | 99 base::AutoLock lock(namespace_->lock); |
| 100 return namespace_->next_texture_id++; | 100 return namespace_->next_texture_id++; |
| 101 } | 101 } |
| 102 virtual void RetireTextureId(WebKit::WebGLId) OVERRIDE { |
| 103 } |
| 102 }; | 104 }; |
| 103 | 105 |
| 104 // Shared data between multiple ResourceProviderContext. This contains mailbox | 106 // Shared data between multiple ResourceProviderContext. This contains mailbox |
| 105 // contents as well as information about sync points. | 107 // contents as well as information about sync points. |
| 106 class ContextSharedData { | 108 class ContextSharedData { |
| 107 public: | 109 public: |
| 108 static scoped_ptr<ContextSharedData> Create() { | 110 static scoped_ptr<ContextSharedData> Create() { |
| 109 return make_scoped_ptr(new ContextSharedData()); | 111 return make_scoped_ptr(new ContextSharedData()); |
| 110 } | 112 } |
| 111 | 113 |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 case ResourceProvider::InvalidType: | 474 case ResourceProvider::InvalidType: |
| 473 NOTREACHED(); | 475 NOTREACHED(); |
| 474 break; | 476 break; |
| 475 } | 477 } |
| 476 CHECK(output_surface_->BindToClient(&output_surface_client_)); | 478 CHECK(output_surface_->BindToClient(&output_surface_client_)); |
| 477 CHECK(child_output_surface_->BindToClient(&child_output_surface_client_)); | 479 CHECK(child_output_surface_->BindToClient(&child_output_surface_client_)); |
| 478 | 480 |
| 479 shared_bitmap_manager_.reset(new TestSharedBitmapManager()); | 481 shared_bitmap_manager_.reset(new TestSharedBitmapManager()); |
| 480 | 482 |
| 481 resource_provider_ = ResourceProvider::Create( | 483 resource_provider_ = ResourceProvider::Create( |
| 482 output_surface_.get(), shared_bitmap_manager_.get(), 0, false); | 484 output_surface_.get(), shared_bitmap_manager_.get(), 0, false, 1); |
| 483 child_resource_provider_ = ResourceProvider::Create( | 485 child_resource_provider_ = ResourceProvider::Create( |
| 484 child_output_surface_.get(), shared_bitmap_manager_.get(), 0, false); | 486 child_output_surface_.get(), |
| 487 shared_bitmap_manager_.get(), |
| 488 0, |
| 489 false, |
| 490 1); |
| 485 } | 491 } |
| 486 | 492 |
| 487 static void CollectResources(ReturnedResourceArray* array, | 493 static void CollectResources(ReturnedResourceArray* array, |
| 488 const ReturnedResourceArray& returned) { | 494 const ReturnedResourceArray& returned) { |
| 489 array->insert(array->end(), returned.begin(), returned.end()); | 495 array->insert(array->end(), returned.begin(), returned.end()); |
| 490 } | 496 } |
| 491 | 497 |
| 492 static ReturnCallback GetReturnCallback(ReturnedResourceArray* array) { | 498 static ReturnCallback GetReturnCallback(ReturnedResourceArray* array) { |
| 493 return base::Bind(&ResourceProviderTest::CollectResources, array); | 499 return base::Bind(&ResourceProviderTest::CollectResources, array); |
| 494 } | 500 } |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1015 if (GetParam() != ResourceProvider::Bitmap) | 1021 if (GetParam() != ResourceProvider::Bitmap) |
| 1016 return; | 1022 return; |
| 1017 | 1023 |
| 1018 scoped_ptr<FakeOutputSurface> parent_output_surface = | 1024 scoped_ptr<FakeOutputSurface> parent_output_surface = |
| 1019 FakeOutputSurface::CreateSoftware( | 1025 FakeOutputSurface::CreateSoftware( |
| 1020 make_scoped_ptr(new SoftwareOutputDevice)); | 1026 make_scoped_ptr(new SoftwareOutputDevice)); |
| 1021 FakeOutputSurfaceClient parent_output_surface_client; | 1027 FakeOutputSurfaceClient parent_output_surface_client; |
| 1022 CHECK(parent_output_surface->BindToClient(&parent_output_surface_client)); | 1028 CHECK(parent_output_surface->BindToClient(&parent_output_surface_client)); |
| 1023 | 1029 |
| 1024 scoped_ptr<ResourceProvider> parent_resource_provider( | 1030 scoped_ptr<ResourceProvider> parent_resource_provider( |
| 1025 ResourceProvider::Create(parent_output_surface.get(), NULL, 0, false)); | 1031 ResourceProvider::Create(parent_output_surface.get(), |
| 1032 NULL, |
| 1033 0, |
| 1034 false, |
| 1035 1)); |
| 1026 | 1036 |
| 1027 gfx::Size size(1, 1); | 1037 gfx::Size size(1, 1); |
| 1028 ResourceFormat format = RGBA_8888; | 1038 ResourceFormat format = RGBA_8888; |
| 1029 size_t pixel_size = TextureSizeBytes(size, format); | 1039 size_t pixel_size = TextureSizeBytes(size, format); |
| 1030 ASSERT_EQ(4U, pixel_size); | 1040 ASSERT_EQ(4U, pixel_size); |
| 1031 | 1041 |
| 1032 ResourceProvider::ResourceId id1 = resource_provider_->CreateResource( | 1042 ResourceProvider::ResourceId id1 = resource_provider_->CreateResource( |
| 1033 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | 1043 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
| 1034 uint8_t data1[4] = { 1, 2, 3, 4 }; | 1044 uint8_t data1[4] = { 1, 2, 3, 4 }; |
| 1035 gfx::Rect rect(size); | 1045 gfx::Rect rect(size); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1069 | 1079 |
| 1070 scoped_ptr<ResourceProviderContext> child_context_owned( | 1080 scoped_ptr<ResourceProviderContext> child_context_owned( |
| 1071 ResourceProviderContext::Create(shared_data_.get())); | 1081 ResourceProviderContext::Create(shared_data_.get())); |
| 1072 | 1082 |
| 1073 FakeOutputSurfaceClient child_output_surface_client; | 1083 FakeOutputSurfaceClient child_output_surface_client; |
| 1074 scoped_ptr<OutputSurface> child_output_surface(FakeOutputSurface::Create3d( | 1084 scoped_ptr<OutputSurface> child_output_surface(FakeOutputSurface::Create3d( |
| 1075 child_context_owned.PassAs<TestWebGraphicsContext3D>())); | 1085 child_context_owned.PassAs<TestWebGraphicsContext3D>())); |
| 1076 CHECK(child_output_surface->BindToClient(&child_output_surface_client)); | 1086 CHECK(child_output_surface->BindToClient(&child_output_surface_client)); |
| 1077 | 1087 |
| 1078 scoped_ptr<ResourceProvider> child_resource_provider( | 1088 scoped_ptr<ResourceProvider> child_resource_provider( |
| 1079 ResourceProvider::Create(child_output_surface.get(), NULL, 0, false)); | 1089 ResourceProvider::Create(child_output_surface.get(), |
| 1090 NULL, |
| 1091 0, |
| 1092 false, |
| 1093 1)); |
| 1080 | 1094 |
| 1081 gfx::Size size(1, 1); | 1095 gfx::Size size(1, 1); |
| 1082 ResourceFormat format = RGBA_8888; | 1096 ResourceFormat format = RGBA_8888; |
| 1083 size_t pixel_size = TextureSizeBytes(size, format); | 1097 size_t pixel_size = TextureSizeBytes(size, format); |
| 1084 ASSERT_EQ(4U, pixel_size); | 1098 ASSERT_EQ(4U, pixel_size); |
| 1085 | 1099 |
| 1086 ResourceProvider::ResourceId id1 = child_resource_provider->CreateResource( | 1100 ResourceProvider::ResourceId id1 = child_resource_provider->CreateResource( |
| 1087 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | 1101 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
| 1088 uint8_t data1[4] = { 1, 2, 3, 4 }; | 1102 uint8_t data1[4] = { 1, 2, 3, 4 }; |
| 1089 gfx::Rect rect(size); | 1103 gfx::Rect rect(size); |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1417 scoped_ptr<TextureStateTrackingContext> child_context_owned( | 1431 scoped_ptr<TextureStateTrackingContext> child_context_owned( |
| 1418 new TextureStateTrackingContext); | 1432 new TextureStateTrackingContext); |
| 1419 TextureStateTrackingContext* child_context = child_context_owned.get(); | 1433 TextureStateTrackingContext* child_context = child_context_owned.get(); |
| 1420 | 1434 |
| 1421 FakeOutputSurfaceClient child_output_surface_client; | 1435 FakeOutputSurfaceClient child_output_surface_client; |
| 1422 scoped_ptr<OutputSurface> child_output_surface(FakeOutputSurface::Create3d( | 1436 scoped_ptr<OutputSurface> child_output_surface(FakeOutputSurface::Create3d( |
| 1423 child_context_owned.PassAs<TestWebGraphicsContext3D>())); | 1437 child_context_owned.PassAs<TestWebGraphicsContext3D>())); |
| 1424 CHECK(child_output_surface->BindToClient(&child_output_surface_client)); | 1438 CHECK(child_output_surface->BindToClient(&child_output_surface_client)); |
| 1425 | 1439 |
| 1426 scoped_ptr<ResourceProvider> child_resource_provider( | 1440 scoped_ptr<ResourceProvider> child_resource_provider( |
| 1427 ResourceProvider::Create(child_output_surface.get(), NULL, 0, false)); | 1441 ResourceProvider::Create(child_output_surface.get(), |
| 1442 NULL, |
| 1443 0, |
| 1444 false, |
| 1445 1)); |
| 1428 | 1446 |
| 1429 scoped_ptr<TextureStateTrackingContext> parent_context_owned( | 1447 scoped_ptr<TextureStateTrackingContext> parent_context_owned( |
| 1430 new TextureStateTrackingContext); | 1448 new TextureStateTrackingContext); |
| 1431 TextureStateTrackingContext* parent_context = parent_context_owned.get(); | 1449 TextureStateTrackingContext* parent_context = parent_context_owned.get(); |
| 1432 | 1450 |
| 1433 FakeOutputSurfaceClient parent_output_surface_client; | 1451 FakeOutputSurfaceClient parent_output_surface_client; |
| 1434 scoped_ptr<OutputSurface> parent_output_surface(FakeOutputSurface::Create3d( | 1452 scoped_ptr<OutputSurface> parent_output_surface(FakeOutputSurface::Create3d( |
| 1435 parent_context_owned.PassAs<TestWebGraphicsContext3D>())); | 1453 parent_context_owned.PassAs<TestWebGraphicsContext3D>())); |
| 1436 CHECK(parent_output_surface->BindToClient(&parent_output_surface_client)); | 1454 CHECK(parent_output_surface->BindToClient(&parent_output_surface_client)); |
| 1437 | 1455 |
| 1438 scoped_ptr<ResourceProvider> parent_resource_provider( | 1456 scoped_ptr<ResourceProvider> parent_resource_provider( |
| 1439 ResourceProvider::Create(parent_output_surface.get(), NULL, 0, false)); | 1457 ResourceProvider::Create(parent_output_surface.get(), |
| 1458 NULL, |
| 1459 0, |
| 1460 false, |
| 1461 1)); |
| 1440 | 1462 |
| 1441 gfx::Size size(1, 1); | 1463 gfx::Size size(1, 1); |
| 1442 ResourceFormat format = RGBA_8888; | 1464 ResourceFormat format = RGBA_8888; |
| 1443 int child_texture_id = 1; | 1465 int child_texture_id = 1; |
| 1444 int parent_texture_id = 2; | 1466 int parent_texture_id = 2; |
| 1445 | 1467 |
| 1446 size_t pixel_size = TextureSizeBytes(size, format); | 1468 size_t pixel_size = TextureSizeBytes(size, format); |
| 1447 ASSERT_EQ(4U, pixel_size); | 1469 ASSERT_EQ(4U, pixel_size); |
| 1448 | 1470 |
| 1449 ResourceProvider::ResourceId id = child_resource_provider->CreateResource( | 1471 ResourceProvider::ResourceId id = child_resource_provider->CreateResource( |
| (...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2030 scoped_ptr<TextureStateTrackingContext> context_owned( | 2052 scoped_ptr<TextureStateTrackingContext> context_owned( |
| 2031 new TextureStateTrackingContext); | 2053 new TextureStateTrackingContext); |
| 2032 TextureStateTrackingContext* context = context_owned.get(); | 2054 TextureStateTrackingContext* context = context_owned.get(); |
| 2033 | 2055 |
| 2034 FakeOutputSurfaceClient output_surface_client; | 2056 FakeOutputSurfaceClient output_surface_client; |
| 2035 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( | 2057 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
| 2036 context_owned.PassAs<TestWebGraphicsContext3D>())); | 2058 context_owned.PassAs<TestWebGraphicsContext3D>())); |
| 2037 CHECK(output_surface->BindToClient(&output_surface_client)); | 2059 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 2038 | 2060 |
| 2039 scoped_ptr<ResourceProvider> resource_provider( | 2061 scoped_ptr<ResourceProvider> resource_provider( |
| 2040 ResourceProvider::Create(output_surface.get(), NULL, 0, false)); | 2062 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); |
| 2041 | 2063 |
| 2042 gfx::Size size(1, 1); | 2064 gfx::Size size(1, 1); |
| 2043 ResourceFormat format = RGBA_8888; | 2065 ResourceFormat format = RGBA_8888; |
| 2044 int texture_id = 1; | 2066 int texture_id = 1; |
| 2045 | 2067 |
| 2046 ResourceProvider::ResourceId id = resource_provider->CreateResource( | 2068 ResourceProvider::ResourceId id = resource_provider->CreateResource( |
| 2047 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | 2069 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
| 2048 | 2070 |
| 2049 // Check that the texture gets created with the right sampler settings. | 2071 // Check that the texture gets created with the right sampler settings. |
| 2050 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)) | 2072 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)) |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2111 scoped_ptr<TextureStateTrackingContext> context_owned( | 2133 scoped_ptr<TextureStateTrackingContext> context_owned( |
| 2112 new TextureStateTrackingContext); | 2134 new TextureStateTrackingContext); |
| 2113 TextureStateTrackingContext* context = context_owned.get(); | 2135 TextureStateTrackingContext* context = context_owned.get(); |
| 2114 | 2136 |
| 2115 FakeOutputSurfaceClient output_surface_client; | 2137 FakeOutputSurfaceClient output_surface_client; |
| 2116 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( | 2138 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
| 2117 context_owned.PassAs<TestWebGraphicsContext3D>())); | 2139 context_owned.PassAs<TestWebGraphicsContext3D>())); |
| 2118 CHECK(output_surface->BindToClient(&output_surface_client)); | 2140 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 2119 | 2141 |
| 2120 scoped_ptr<ResourceProvider> resource_provider( | 2142 scoped_ptr<ResourceProvider> resource_provider( |
| 2121 ResourceProvider::Create(output_surface.get(), NULL, 0, false)); | 2143 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); |
| 2122 | 2144 |
| 2123 gfx::Size size(1, 1); | 2145 gfx::Size size(1, 1); |
| 2124 ResourceFormat format = RGBA_8888; | 2146 ResourceFormat format = RGBA_8888; |
| 2125 int texture_id = 1; | 2147 int texture_id = 1; |
| 2126 | 2148 |
| 2127 // Check that the texture gets created with the right sampler settings. | 2149 // Check that the texture gets created with the right sampler settings. |
| 2128 ResourceProvider::ResourceId id = resource_provider->CreateManagedResource( | 2150 ResourceProvider::ResourceId id = resource_provider->CreateManagedResource( |
| 2129 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | 2151 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
| 2130 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)); | 2152 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)); |
| 2131 EXPECT_CALL(*context, | 2153 EXPECT_CALL(*context, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2156 scoped_ptr<TextureStateTrackingContext> context_owned( | 2178 scoped_ptr<TextureStateTrackingContext> context_owned( |
| 2157 new TextureStateTrackingContext); | 2179 new TextureStateTrackingContext); |
| 2158 TextureStateTrackingContext* context = context_owned.get(); | 2180 TextureStateTrackingContext* context = context_owned.get(); |
| 2159 | 2181 |
| 2160 FakeOutputSurfaceClient output_surface_client; | 2182 FakeOutputSurfaceClient output_surface_client; |
| 2161 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( | 2183 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
| 2162 context_owned.PassAs<TestWebGraphicsContext3D>())); | 2184 context_owned.PassAs<TestWebGraphicsContext3D>())); |
| 2163 CHECK(output_surface->BindToClient(&output_surface_client)); | 2185 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 2164 | 2186 |
| 2165 scoped_ptr<ResourceProvider> resource_provider( | 2187 scoped_ptr<ResourceProvider> resource_provider( |
| 2166 ResourceProvider::Create(output_surface.get(), NULL, 0, false)); | 2188 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); |
| 2167 | 2189 |
| 2168 gfx::Size size(1, 1); | 2190 gfx::Size size(1, 1); |
| 2169 ResourceFormat format = RGBA_8888; | 2191 ResourceFormat format = RGBA_8888; |
| 2170 GLenum texture_pool = GL_TEXTURE_POOL_UNMANAGED_CHROMIUM; | 2192 GLenum texture_pool = GL_TEXTURE_POOL_UNMANAGED_CHROMIUM; |
| 2171 | 2193 |
| 2172 for (int texture_id = 1; texture_id <= 2; ++texture_id) { | 2194 for (int texture_id = 1; texture_id <= 2; ++texture_id) { |
| 2173 GLint wrap_mode = texture_id == 1 ? GL_CLAMP_TO_EDGE : GL_REPEAT; | 2195 GLint wrap_mode = texture_id == 1 ? GL_CLAMP_TO_EDGE : GL_REPEAT; |
| 2174 // Check that the texture gets created with the right sampler settings. | 2196 // Check that the texture gets created with the right sampler settings. |
| 2175 ResourceProvider::ResourceId id = | 2197 ResourceProvider::ResourceId id = |
| 2176 resource_provider->CreateGLTexture(size, | 2198 resource_provider->CreateGLTexture(size, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2209 scoped_ptr<base::SharedMemory> shared_memory( | 2231 scoped_ptr<base::SharedMemory> shared_memory( |
| 2210 CreateAndFillSharedMemory(size, kBadBeef)); | 2232 CreateAndFillSharedMemory(size, kBadBeef)); |
| 2211 | 2233 |
| 2212 FakeOutputSurfaceClient output_surface_client; | 2234 FakeOutputSurfaceClient output_surface_client; |
| 2213 scoped_ptr<OutputSurface> output_surface( | 2235 scoped_ptr<OutputSurface> output_surface( |
| 2214 FakeOutputSurface::CreateSoftware(make_scoped_ptr( | 2236 FakeOutputSurface::CreateSoftware(make_scoped_ptr( |
| 2215 new SoftwareOutputDevice))); | 2237 new SoftwareOutputDevice))); |
| 2216 CHECK(output_surface->BindToClient(&output_surface_client)); | 2238 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 2217 | 2239 |
| 2218 scoped_ptr<ResourceProvider> resource_provider( | 2240 scoped_ptr<ResourceProvider> resource_provider( |
| 2219 ResourceProvider::Create(output_surface.get(), NULL, 0, false)); | 2241 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); |
| 2220 | 2242 |
| 2221 scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( | 2243 scoped_ptr<SingleReleaseCallback> callback = SingleReleaseCallback::Create( |
| 2222 base::Bind(&EmptyReleaseCallback)); | 2244 base::Bind(&EmptyReleaseCallback)); |
| 2223 TextureMailbox mailbox(shared_memory.get(), size); | 2245 TextureMailbox mailbox(shared_memory.get(), size); |
| 2224 | 2246 |
| 2225 ResourceProvider::ResourceId id = | 2247 ResourceProvider::ResourceId id = |
| 2226 resource_provider->CreateResourceFromTextureMailbox( | 2248 resource_provider->CreateResourceFromTextureMailbox( |
| 2227 mailbox, callback.Pass()); | 2249 mailbox, callback.Pass()); |
| 2228 EXPECT_NE(0u, id); | 2250 EXPECT_NE(0u, id); |
| 2229 | 2251 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2244 scoped_ptr<TextureStateTrackingContext> context_owned( | 2266 scoped_ptr<TextureStateTrackingContext> context_owned( |
| 2245 new TextureStateTrackingContext); | 2267 new TextureStateTrackingContext); |
| 2246 TextureStateTrackingContext* context = context_owned.get(); | 2268 TextureStateTrackingContext* context = context_owned.get(); |
| 2247 | 2269 |
| 2248 FakeOutputSurfaceClient output_surface_client; | 2270 FakeOutputSurfaceClient output_surface_client; |
| 2249 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( | 2271 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
| 2250 context_owned.PassAs<TestWebGraphicsContext3D>())); | 2272 context_owned.PassAs<TestWebGraphicsContext3D>())); |
| 2251 CHECK(output_surface->BindToClient(&output_surface_client)); | 2273 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 2252 | 2274 |
| 2253 scoped_ptr<ResourceProvider> resource_provider( | 2275 scoped_ptr<ResourceProvider> resource_provider( |
| 2254 ResourceProvider::Create(output_surface.get(), NULL, 0, false)); | 2276 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); |
| 2255 | 2277 |
| 2256 unsigned texture_id = 1; | 2278 unsigned texture_id = 1; |
| 2257 unsigned sync_point = 30; | 2279 unsigned sync_point = 30; |
| 2258 unsigned target = GL_TEXTURE_2D; | 2280 unsigned target = GL_TEXTURE_2D; |
| 2259 | 2281 |
| 2260 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); | 2282 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); |
| 2261 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); | 2283 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); |
| 2262 EXPECT_CALL(*context, insertSyncPoint()).Times(0); | 2284 EXPECT_CALL(*context, insertSyncPoint()).Times(0); |
| 2263 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); | 2285 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); |
| 2264 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); | 2286 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2308 scoped_ptr<TextureStateTrackingContext> context_owned( | 2330 scoped_ptr<TextureStateTrackingContext> context_owned( |
| 2309 new TextureStateTrackingContext); | 2331 new TextureStateTrackingContext); |
| 2310 TextureStateTrackingContext* context = context_owned.get(); | 2332 TextureStateTrackingContext* context = context_owned.get(); |
| 2311 | 2333 |
| 2312 FakeOutputSurfaceClient output_surface_client; | 2334 FakeOutputSurfaceClient output_surface_client; |
| 2313 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( | 2335 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
| 2314 context_owned.PassAs<TestWebGraphicsContext3D>())); | 2336 context_owned.PassAs<TestWebGraphicsContext3D>())); |
| 2315 CHECK(output_surface->BindToClient(&output_surface_client)); | 2337 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 2316 | 2338 |
| 2317 scoped_ptr<ResourceProvider> resource_provider( | 2339 scoped_ptr<ResourceProvider> resource_provider( |
| 2318 ResourceProvider::Create(output_surface.get(), NULL, 0, false)); | 2340 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); |
| 2319 | 2341 |
| 2320 unsigned texture_id = 1; | 2342 unsigned texture_id = 1; |
| 2321 unsigned sync_point = 30; | 2343 unsigned sync_point = 30; |
| 2322 unsigned target = GL_TEXTURE_EXTERNAL_OES; | 2344 unsigned target = GL_TEXTURE_EXTERNAL_OES; |
| 2323 | 2345 |
| 2324 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); | 2346 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); |
| 2325 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); | 2347 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); |
| 2326 EXPECT_CALL(*context, insertSyncPoint()).Times(0); | 2348 EXPECT_CALL(*context, insertSyncPoint()).Times(0); |
| 2327 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); | 2349 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); |
| 2328 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); | 2350 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 2359 EXPECT_CALL(*context, insertSyncPoint()); | 2381 EXPECT_CALL(*context, insertSyncPoint()); |
| 2360 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); | 2382 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); |
| 2361 | 2383 |
| 2362 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); | 2384 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); |
| 2363 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); | 2385 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); |
| 2364 } | 2386 } |
| 2365 } | 2387 } |
| 2366 | 2388 |
| 2367 class AllocationTrackingContext3D : public TestWebGraphicsContext3D { | 2389 class AllocationTrackingContext3D : public TestWebGraphicsContext3D { |
| 2368 public: | 2390 public: |
| 2369 MOCK_METHOD0(createTexture, WebGLId()); | 2391 MOCK_METHOD0(NextTextureId, WebGLId()); |
| 2370 MOCK_METHOD1(deleteTexture, void(WebGLId texture_id)); | 2392 MOCK_METHOD1(RetireTextureId, void(WebGLId id)); |
| 2371 MOCK_METHOD2(bindTexture, void(WGC3Denum target, WebGLId texture)); | 2393 MOCK_METHOD2(bindTexture, void(WGC3Denum target, WebGLId texture)); |
| 2372 MOCK_METHOD9(texImage2D, | 2394 MOCK_METHOD9(texImage2D, |
| 2373 void(WGC3Denum target, | 2395 void(WGC3Denum target, |
| 2374 WGC3Dint level, | 2396 WGC3Dint level, |
| 2375 WGC3Denum internalformat, | 2397 WGC3Denum internalformat, |
| 2376 WGC3Dsizei width, | 2398 WGC3Dsizei width, |
| 2377 WGC3Dsizei height, | 2399 WGC3Dsizei height, |
| 2378 WGC3Dint border, | 2400 WGC3Dint border, |
| 2379 WGC3Denum format, | 2401 WGC3Denum format, |
| 2380 WGC3Denum type, | 2402 WGC3Denum type, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2437 scoped_ptr<AllocationTrackingContext3D> context_owned( | 2459 scoped_ptr<AllocationTrackingContext3D> context_owned( |
| 2438 new StrictMock<AllocationTrackingContext3D>); | 2460 new StrictMock<AllocationTrackingContext3D>); |
| 2439 AllocationTrackingContext3D* context = context_owned.get(); | 2461 AllocationTrackingContext3D* context = context_owned.get(); |
| 2440 | 2462 |
| 2441 FakeOutputSurfaceClient output_surface_client; | 2463 FakeOutputSurfaceClient output_surface_client; |
| 2442 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( | 2464 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
| 2443 context_owned.PassAs<TestWebGraphicsContext3D>())); | 2465 context_owned.PassAs<TestWebGraphicsContext3D>())); |
| 2444 CHECK(output_surface->BindToClient(&output_surface_client)); | 2466 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 2445 | 2467 |
| 2446 scoped_ptr<ResourceProvider> resource_provider( | 2468 scoped_ptr<ResourceProvider> resource_provider( |
| 2447 ResourceProvider::Create(output_surface.get(), NULL, 0, false)); | 2469 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); |
| 2448 | 2470 |
| 2449 gfx::Size size(2, 2); | 2471 gfx::Size size(2, 2); |
| 2450 gfx::Vector2d offset(0, 0); | 2472 gfx::Vector2d offset(0, 0); |
| 2451 gfx::Rect rect(0, 0, 2, 2); | 2473 gfx::Rect rect(0, 0, 2, 2); |
| 2452 ResourceFormat format = RGBA_8888; | 2474 ResourceFormat format = RGBA_8888; |
| 2453 ResourceProvider::ResourceId id = 0; | 2475 ResourceProvider::ResourceId id = 0; |
| 2454 uint8_t pixels[16] = { 0 }; | 2476 uint8_t pixels[16] = { 0 }; |
| 2455 int texture_id = 123; | 2477 int texture_id = 123; |
| 2456 | 2478 |
| 2457 // Lazy allocation. Don't allocate when creating the resource. | 2479 // Lazy allocation. Don't allocate when creating the resource. |
| 2458 id = resource_provider->CreateResource( | 2480 id = resource_provider->CreateResource( |
| 2459 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | 2481 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
| 2460 | 2482 |
| 2461 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id)); | 2483 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); |
| 2462 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1); | 2484 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1); |
| 2463 resource_provider->CreateForTesting(id); | 2485 resource_provider->CreateForTesting(id); |
| 2464 | 2486 |
| 2465 EXPECT_CALL(*context, deleteTexture(texture_id)).Times(1); | 2487 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); |
| 2466 resource_provider->DeleteResource(id); | 2488 resource_provider->DeleteResource(id); |
| 2467 | 2489 |
| 2468 Mock::VerifyAndClearExpectations(context); | 2490 Mock::VerifyAndClearExpectations(context); |
| 2469 | 2491 |
| 2470 // Do allocate when we set the pixels. | 2492 // Do allocate when we set the pixels. |
| 2471 id = resource_provider->CreateResource( | 2493 id = resource_provider->CreateResource( |
| 2472 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | 2494 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
| 2473 | 2495 |
| 2474 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id)); | 2496 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); |
| 2475 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(3); | 2497 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(3); |
| 2476 EXPECT_CALL(*context, texImage2D(_, _, _, 2, 2, _, _, _, _)).Times(1); | 2498 EXPECT_CALL(*context, texImage2D(_, _, _, 2, 2, _, _, _, _)).Times(1); |
| 2477 EXPECT_CALL(*context, texSubImage2D(_, _, _, _, 2, 2, _, _, _)).Times(1); | 2499 EXPECT_CALL(*context, texSubImage2D(_, _, _, _, 2, 2, _, _, _)).Times(1); |
| 2478 resource_provider->SetPixels(id, pixels, rect, rect, offset); | 2500 resource_provider->SetPixels(id, pixels, rect, rect, offset); |
| 2479 | 2501 |
| 2480 EXPECT_CALL(*context, deleteTexture(texture_id)).Times(1); | 2502 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); |
| 2481 resource_provider->DeleteResource(id); | 2503 resource_provider->DeleteResource(id); |
| 2482 | 2504 |
| 2483 Mock::VerifyAndClearExpectations(context); | 2505 Mock::VerifyAndClearExpectations(context); |
| 2484 | 2506 |
| 2485 // Same for async version. | 2507 // Same for async version. |
| 2486 id = resource_provider->CreateResource( | 2508 id = resource_provider->CreateResource( |
| 2487 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | 2509 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
| 2488 resource_provider->AcquirePixelBuffer(id); | 2510 resource_provider->AcquirePixelBuffer(id); |
| 2489 | 2511 |
| 2490 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id)); | 2512 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); |
| 2491 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); | 2513 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); |
| 2492 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) | 2514 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) |
| 2493 .Times(1); | 2515 .Times(1); |
| 2494 resource_provider->BeginSetPixels(id); | 2516 resource_provider->BeginSetPixels(id); |
| 2495 ASSERT_TRUE(resource_provider->DidSetPixelsComplete(id)); | 2517 ASSERT_TRUE(resource_provider->DidSetPixelsComplete(id)); |
| 2496 | 2518 |
| 2497 resource_provider->ReleasePixelBuffer(id); | 2519 resource_provider->ReleasePixelBuffer(id); |
| 2498 | 2520 |
| 2499 EXPECT_CALL(*context, deleteTexture(texture_id)).Times(1); | 2521 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); |
| 2500 resource_provider->DeleteResource(id); | 2522 resource_provider->DeleteResource(id); |
| 2501 | 2523 |
| 2502 Mock::VerifyAndClearExpectations(context); | 2524 Mock::VerifyAndClearExpectations(context); |
| 2503 } | 2525 } |
| 2504 | 2526 |
| 2505 TEST_P(ResourceProviderTest, PixelBuffer_GLTexture) { | 2527 TEST_P(ResourceProviderTest, PixelBuffer_GLTexture) { |
| 2506 if (GetParam() != ResourceProvider::GLTexture) | 2528 if (GetParam() != ResourceProvider::GLTexture) |
| 2507 return; | 2529 return; |
| 2508 scoped_ptr<AllocationTrackingContext3D> context_owned( | 2530 scoped_ptr<AllocationTrackingContext3D> context_owned( |
| 2509 new StrictMock<AllocationTrackingContext3D>); | 2531 new StrictMock<AllocationTrackingContext3D>); |
| 2510 AllocationTrackingContext3D* context = context_owned.get(); | 2532 AllocationTrackingContext3D* context = context_owned.get(); |
| 2511 | 2533 |
| 2512 FakeOutputSurfaceClient output_surface_client; | 2534 FakeOutputSurfaceClient output_surface_client; |
| 2513 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( | 2535 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
| 2514 context_owned.PassAs<TestWebGraphicsContext3D>())); | 2536 context_owned.PassAs<TestWebGraphicsContext3D>())); |
| 2515 CHECK(output_surface->BindToClient(&output_surface_client)); | 2537 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 2516 | 2538 |
| 2517 gfx::Size size(2, 2); | 2539 gfx::Size size(2, 2); |
| 2518 ResourceFormat format = RGBA_8888; | 2540 ResourceFormat format = RGBA_8888; |
| 2519 ResourceProvider::ResourceId id = 0; | 2541 ResourceProvider::ResourceId id = 0; |
| 2520 int texture_id = 123; | 2542 int texture_id = 123; |
| 2521 | 2543 |
| 2522 scoped_ptr<ResourceProvider> resource_provider( | 2544 scoped_ptr<ResourceProvider> resource_provider( |
| 2523 ResourceProvider::Create(output_surface.get(), NULL, 0, false)); | 2545 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); |
| 2524 | 2546 |
| 2525 id = resource_provider->CreateResource( | 2547 id = resource_provider->CreateResource( |
| 2526 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | 2548 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
| 2527 resource_provider->AcquirePixelBuffer(id); | 2549 resource_provider->AcquirePixelBuffer(id); |
| 2528 | 2550 |
| 2529 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id)); | 2551 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); |
| 2530 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); | 2552 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); |
| 2531 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) | 2553 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) |
| 2532 .Times(1); | 2554 .Times(1); |
| 2533 resource_provider->BeginSetPixels(id); | 2555 resource_provider->BeginSetPixels(id); |
| 2534 | 2556 |
| 2535 EXPECT_TRUE(resource_provider->DidSetPixelsComplete(id)); | 2557 EXPECT_TRUE(resource_provider->DidSetPixelsComplete(id)); |
| 2536 | 2558 |
| 2537 resource_provider->ReleasePixelBuffer(id); | 2559 resource_provider->ReleasePixelBuffer(id); |
| 2538 | 2560 |
| 2539 EXPECT_CALL(*context, deleteTexture(texture_id)).Times(1); | 2561 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); |
| 2540 resource_provider->DeleteResource(id); | 2562 resource_provider->DeleteResource(id); |
| 2541 | 2563 |
| 2542 Mock::VerifyAndClearExpectations(context); | 2564 Mock::VerifyAndClearExpectations(context); |
| 2543 } | 2565 } |
| 2544 | 2566 |
| 2545 TEST_P(ResourceProviderTest, PixelBuffer_Bitmap) { | 2567 TEST_P(ResourceProviderTest, PixelBuffer_Bitmap) { |
| 2546 if (GetParam() != ResourceProvider::Bitmap) | 2568 if (GetParam() != ResourceProvider::Bitmap) |
| 2547 return; | 2569 return; |
| 2548 FakeOutputSurfaceClient output_surface_client; | 2570 FakeOutputSurfaceClient output_surface_client; |
| 2549 scoped_ptr<OutputSurface> output_surface( | 2571 scoped_ptr<OutputSurface> output_surface( |
| 2550 FakeOutputSurface::CreateSoftware(make_scoped_ptr( | 2572 FakeOutputSurface::CreateSoftware(make_scoped_ptr( |
| 2551 new SoftwareOutputDevice))); | 2573 new SoftwareOutputDevice))); |
| 2552 CHECK(output_surface->BindToClient(&output_surface_client)); | 2574 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 2553 | 2575 |
| 2554 gfx::Size size(1, 1); | 2576 gfx::Size size(1, 1); |
| 2555 ResourceFormat format = RGBA_8888; | 2577 ResourceFormat format = RGBA_8888; |
| 2556 ResourceProvider::ResourceId id = 0; | 2578 ResourceProvider::ResourceId id = 0; |
| 2557 const uint32_t kBadBeef = 0xbadbeef; | 2579 const uint32_t kBadBeef = 0xbadbeef; |
| 2558 | 2580 |
| 2559 scoped_ptr<ResourceProvider> resource_provider( | 2581 scoped_ptr<ResourceProvider> resource_provider( |
| 2560 ResourceProvider::Create(output_surface.get(), NULL, 0, false)); | 2582 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); |
| 2561 | 2583 |
| 2562 id = resource_provider->CreateResource( | 2584 id = resource_provider->CreateResource( |
| 2563 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | 2585 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
| 2564 resource_provider->AcquirePixelBuffer(id); | 2586 resource_provider->AcquirePixelBuffer(id); |
| 2565 | 2587 |
| 2566 void* data = resource_provider->MapPixelBuffer(id); | 2588 void* data = resource_provider->MapPixelBuffer(id); |
| 2567 ASSERT_TRUE(!!data); | 2589 ASSERT_TRUE(!!data); |
| 2568 memcpy(data, &kBadBeef, sizeof(kBadBeef)); | 2590 memcpy(data, &kBadBeef, sizeof(kBadBeef)); |
| 2569 resource_provider->UnmapPixelBuffer(id); | 2591 resource_provider->UnmapPixelBuffer(id); |
| 2570 | 2592 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2596 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( | 2618 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
| 2597 context_owned.PassAs<TestWebGraphicsContext3D>())); | 2619 context_owned.PassAs<TestWebGraphicsContext3D>())); |
| 2598 CHECK(output_surface->BindToClient(&output_surface_client)); | 2620 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 2599 | 2621 |
| 2600 gfx::Size size(2, 2); | 2622 gfx::Size size(2, 2); |
| 2601 ResourceFormat format = RGBA_8888; | 2623 ResourceFormat format = RGBA_8888; |
| 2602 ResourceProvider::ResourceId id = 0; | 2624 ResourceProvider::ResourceId id = 0; |
| 2603 int texture_id = 123; | 2625 int texture_id = 123; |
| 2604 | 2626 |
| 2605 scoped_ptr<ResourceProvider> resource_provider( | 2627 scoped_ptr<ResourceProvider> resource_provider( |
| 2606 ResourceProvider::Create(output_surface.get(), NULL, 0, false)); | 2628 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); |
| 2607 | 2629 |
| 2608 id = resource_provider->CreateResource( | 2630 id = resource_provider->CreateResource( |
| 2609 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | 2631 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
| 2610 resource_provider->AcquirePixelBuffer(id); | 2632 resource_provider->AcquirePixelBuffer(id); |
| 2611 | 2633 |
| 2612 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id)); | 2634 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); |
| 2613 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); | 2635 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); |
| 2614 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) | 2636 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) |
| 2615 .Times(1); | 2637 .Times(1); |
| 2616 resource_provider->BeginSetPixels(id); | 2638 resource_provider->BeginSetPixels(id); |
| 2617 | 2639 |
| 2618 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1); | 2640 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1); |
| 2619 EXPECT_CALL(*context, waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)).Times(1); | 2641 EXPECT_CALL(*context, waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)).Times(1); |
| 2620 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, 0)).Times(1); | 2642 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, 0)).Times(1); |
| 2621 resource_provider->ForceSetPixelsToComplete(id); | 2643 resource_provider->ForceSetPixelsToComplete(id); |
| 2622 | 2644 |
| 2623 resource_provider->ReleasePixelBuffer(id); | 2645 resource_provider->ReleasePixelBuffer(id); |
| 2624 | 2646 |
| 2625 EXPECT_CALL(*context, deleteTexture(texture_id)).Times(1); | 2647 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); |
| 2626 resource_provider->DeleteResource(id); | 2648 resource_provider->DeleteResource(id); |
| 2627 | 2649 |
| 2628 Mock::VerifyAndClearExpectations(context); | 2650 Mock::VerifyAndClearExpectations(context); |
| 2629 } | 2651 } |
| 2630 | 2652 |
| 2631 TEST_P(ResourceProviderTest, PixelBufferLostContext) { | 2653 TEST_P(ResourceProviderTest, PixelBufferLostContext) { |
| 2632 scoped_ptr<AllocationTrackingContext3D> context_owned( | 2654 scoped_ptr<AllocationTrackingContext3D> context_owned( |
| 2633 new NiceMock<AllocationTrackingContext3D>); | 2655 new NiceMock<AllocationTrackingContext3D>); |
| 2634 AllocationTrackingContext3D* context = context_owned.get(); | 2656 AllocationTrackingContext3D* context = context_owned.get(); |
| 2635 | 2657 |
| 2636 FakeOutputSurfaceClient output_surface_client; | 2658 FakeOutputSurfaceClient output_surface_client; |
| 2637 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( | 2659 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
| 2638 context_owned.PassAs<TestWebGraphicsContext3D>())); | 2660 context_owned.PassAs<TestWebGraphicsContext3D>())); |
| 2639 CHECK(output_surface->BindToClient(&output_surface_client)); | 2661 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 2640 | 2662 |
| 2641 gfx::Size size(2, 2); | 2663 gfx::Size size(2, 2); |
| 2642 ResourceFormat format = RGBA_8888; | 2664 ResourceFormat format = RGBA_8888; |
| 2643 ResourceProvider::ResourceId id = 0; | 2665 ResourceProvider::ResourceId id = 0; |
| 2644 int texture_id = 123; | 2666 int texture_id = 123; |
| 2645 | 2667 |
| 2646 scoped_ptr<ResourceProvider> resource_provider( | 2668 scoped_ptr<ResourceProvider> resource_provider( |
| 2647 ResourceProvider::Create(output_surface.get(), NULL, 0, false)); | 2669 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); |
| 2648 | 2670 |
| 2649 EXPECT_CALL(*context, createTexture()).WillRepeatedly(Return(texture_id)); | 2671 EXPECT_CALL(*context, NextTextureId()).WillRepeatedly(Return(texture_id)); |
| 2650 | 2672 |
| 2651 id = resource_provider->CreateResource( | 2673 id = resource_provider->CreateResource( |
| 2652 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | 2674 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
| 2653 context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, | 2675 context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, |
| 2654 GL_INNOCENT_CONTEXT_RESET_ARB); | 2676 GL_INNOCENT_CONTEXT_RESET_ARB); |
| 2655 resource_provider->AcquirePixelBuffer(id); | 2677 resource_provider->AcquirePixelBuffer(id); |
| 2656 uint8_t* buffer = resource_provider->MapPixelBuffer(id); | 2678 uint8_t* buffer = resource_provider->MapPixelBuffer(id); |
| 2657 EXPECT_TRUE(buffer == NULL); | 2679 EXPECT_TRUE(buffer == NULL); |
| 2658 resource_provider->UnmapPixelBuffer(id); | 2680 resource_provider->UnmapPixelBuffer(id); |
| 2659 resource_provider->ReleasePixelBuffer(id); | 2681 resource_provider->ReleasePixelBuffer(id); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2675 | 2697 |
| 2676 const int kWidth = 2; | 2698 const int kWidth = 2; |
| 2677 const int kHeight = 2; | 2699 const int kHeight = 2; |
| 2678 gfx::Size size(kWidth, kHeight); | 2700 gfx::Size size(kWidth, kHeight); |
| 2679 ResourceFormat format = RGBA_8888; | 2701 ResourceFormat format = RGBA_8888; |
| 2680 ResourceProvider::ResourceId id = 0; | 2702 ResourceProvider::ResourceId id = 0; |
| 2681 const unsigned kTextureId = 123u; | 2703 const unsigned kTextureId = 123u; |
| 2682 const unsigned kImageId = 234u; | 2704 const unsigned kImageId = 234u; |
| 2683 | 2705 |
| 2684 scoped_ptr<ResourceProvider> resource_provider( | 2706 scoped_ptr<ResourceProvider> resource_provider( |
| 2685 ResourceProvider::Create(output_surface.get(), NULL, 0, false)); | 2707 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); |
| 2686 | 2708 |
| 2687 id = resource_provider->CreateResource( | 2709 id = resource_provider->CreateResource( |
| 2688 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | 2710 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
| 2689 EXPECT_CALL(*context, createImageCHROMIUM(kWidth, kHeight, GL_RGBA8_OES)) | 2711 EXPECT_CALL(*context, createImageCHROMIUM(kWidth, kHeight, GL_RGBA8_OES)) |
| 2690 .WillOnce(Return(kImageId)) | 2712 .WillOnce(Return(kImageId)) |
| 2691 .RetiresOnSaturation(); | 2713 .RetiresOnSaturation(); |
| 2692 resource_provider->AcquireImage(id); | 2714 resource_provider->AcquireImage(id); |
| 2693 | 2715 |
| 2694 void* dummy_mapped_buffer_address = NULL; | 2716 void* dummy_mapped_buffer_address = NULL; |
| 2695 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId, GL_READ_WRITE)) | 2717 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId, GL_READ_WRITE)) |
| 2696 .WillOnce(Return(dummy_mapped_buffer_address)) | 2718 .WillOnce(Return(dummy_mapped_buffer_address)) |
| 2697 .RetiresOnSaturation(); | 2719 .RetiresOnSaturation(); |
| 2698 resource_provider->MapImage(id); | 2720 resource_provider->MapImage(id); |
| 2699 | 2721 |
| 2700 const int kStride = 4; | 2722 const int kStride = 4; |
| 2701 EXPECT_CALL(*context, getImageParameterivCHROMIUM(kImageId, | 2723 EXPECT_CALL(*context, getImageParameterivCHROMIUM(kImageId, |
| 2702 GL_IMAGE_ROWBYTES_CHROMIUM, | 2724 GL_IMAGE_ROWBYTES_CHROMIUM, |
| 2703 _)) | 2725 _)) |
| 2704 .WillOnce(SetArgPointee<2>(kStride)) | 2726 .WillOnce(SetArgPointee<2>(kStride)) |
| 2705 .RetiresOnSaturation(); | 2727 .RetiresOnSaturation(); |
| 2706 int stride = resource_provider->GetImageStride(id); | 2728 int stride = resource_provider->GetImageStride(id); |
| 2707 EXPECT_EQ(kStride, stride); | 2729 EXPECT_EQ(kStride, stride); |
| 2708 | 2730 |
| 2709 EXPECT_CALL(*context, unmapImageCHROMIUM(kImageId)) | 2731 EXPECT_CALL(*context, unmapImageCHROMIUM(kImageId)) |
| 2710 .Times(1) | 2732 .Times(1) |
| 2711 .RetiresOnSaturation(); | 2733 .RetiresOnSaturation(); |
| 2712 resource_provider->UnmapImage(id); | 2734 resource_provider->UnmapImage(id); |
| 2713 | 2735 |
| 2714 EXPECT_CALL(*context, createTexture()) | 2736 EXPECT_CALL(*context, NextTextureId()) |
| 2715 .WillOnce(Return(kTextureId)) | 2737 .WillOnce(Return(kTextureId)) |
| 2716 .RetiresOnSaturation(); | 2738 .RetiresOnSaturation(); |
| 2717 // Once in CreateTextureId and once in BindForSampling | 2739 // Once in CreateTextureId and once in BindForSampling |
| 2718 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(2) | 2740 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(2) |
| 2719 .RetiresOnSaturation(); | 2741 .RetiresOnSaturation(); |
| 2720 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) | 2742 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) |
| 2721 .Times(1) | 2743 .Times(1) |
| 2722 .RetiresOnSaturation(); | 2744 .RetiresOnSaturation(); |
| 2723 { | 2745 { |
| 2724 ResourceProvider::ScopedSamplerGL lock_gl( | 2746 ResourceProvider::ScopedSamplerGL lock_gl( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2737 resource_provider->UnmapImage(id); | 2759 resource_provider->UnmapImage(id); |
| 2738 | 2760 |
| 2739 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(1) | 2761 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(1) |
| 2740 .RetiresOnSaturation(); | 2762 .RetiresOnSaturation(); |
| 2741 EXPECT_CALL(*context, releaseTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) | 2763 EXPECT_CALL(*context, releaseTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) |
| 2742 .Times(1) | 2764 .Times(1) |
| 2743 .RetiresOnSaturation(); | 2765 .RetiresOnSaturation(); |
| 2744 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) | 2766 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) |
| 2745 .Times(1) | 2767 .Times(1) |
| 2746 .RetiresOnSaturation(); | 2768 .RetiresOnSaturation(); |
| 2747 EXPECT_CALL(*context, deleteTexture(kTextureId)) | 2769 EXPECT_CALL(*context, RetireTextureId(kTextureId)) |
| 2748 .Times(1) | 2770 .Times(1) |
| 2749 .RetiresOnSaturation(); | 2771 .RetiresOnSaturation(); |
| 2750 { | 2772 { |
| 2751 ResourceProvider::ScopedSamplerGL lock_gl( | 2773 ResourceProvider::ScopedSamplerGL lock_gl( |
| 2752 resource_provider.get(), id, GL_TEXTURE_2D, GL_LINEAR); | 2774 resource_provider.get(), id, GL_TEXTURE_2D, GL_LINEAR); |
| 2753 EXPECT_EQ(kTextureId, lock_gl.texture_id()); | 2775 EXPECT_EQ(kTextureId, lock_gl.texture_id()); |
| 2754 } | 2776 } |
| 2755 | 2777 |
| 2756 EXPECT_CALL(*context, destroyImageCHROMIUM(kImageId)) | 2778 EXPECT_CALL(*context, destroyImageCHROMIUM(kImageId)) |
| 2757 .Times(1) | 2779 .Times(1) |
| 2758 .RetiresOnSaturation(); | 2780 .RetiresOnSaturation(); |
| 2759 resource_provider->ReleaseImage(id); | 2781 resource_provider->ReleaseImage(id); |
| 2760 } | 2782 } |
| 2761 | 2783 |
| 2762 TEST_P(ResourceProviderTest, Image_Bitmap) { | 2784 TEST_P(ResourceProviderTest, Image_Bitmap) { |
| 2763 if (GetParam() != ResourceProvider::Bitmap) | 2785 if (GetParam() != ResourceProvider::Bitmap) |
| 2764 return; | 2786 return; |
| 2765 FakeOutputSurfaceClient output_surface_client; | 2787 FakeOutputSurfaceClient output_surface_client; |
| 2766 scoped_ptr<OutputSurface> output_surface( | 2788 scoped_ptr<OutputSurface> output_surface( |
| 2767 FakeOutputSurface::CreateSoftware(make_scoped_ptr( | 2789 FakeOutputSurface::CreateSoftware(make_scoped_ptr( |
| 2768 new SoftwareOutputDevice))); | 2790 new SoftwareOutputDevice))); |
| 2769 CHECK(output_surface->BindToClient(&output_surface_client)); | 2791 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 2770 | 2792 |
| 2771 gfx::Size size(1, 1); | 2793 gfx::Size size(1, 1); |
| 2772 ResourceFormat format = RGBA_8888; | 2794 ResourceFormat format = RGBA_8888; |
| 2773 ResourceProvider::ResourceId id = 0; | 2795 ResourceProvider::ResourceId id = 0; |
| 2774 const uint32_t kBadBeef = 0xbadbeef; | 2796 const uint32_t kBadBeef = 0xbadbeef; |
| 2775 | 2797 |
| 2776 scoped_ptr<ResourceProvider> resource_provider( | 2798 scoped_ptr<ResourceProvider> resource_provider( |
| 2777 ResourceProvider::Create(output_surface.get(), NULL, 0, false)); | 2799 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); |
| 2778 | 2800 |
| 2779 id = resource_provider->CreateResource( | 2801 id = resource_provider->CreateResource( |
| 2780 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | 2802 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
| 2781 resource_provider->AcquireImage(id); | 2803 resource_provider->AcquireImage(id); |
| 2782 | 2804 |
| 2783 const int kStride = 0; | 2805 const int kStride = 0; |
| 2784 int stride = resource_provider->GetImageStride(id); | 2806 int stride = resource_provider->GetImageStride(id); |
| 2785 EXPECT_EQ(kStride, stride); | 2807 EXPECT_EQ(kStride, stride); |
| 2786 | 2808 |
| 2787 void* data = resource_provider->MapImage(id); | 2809 void* data = resource_provider->MapImage(id); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 2818 } | 2840 } |
| 2819 | 2841 |
| 2820 TEST(ResourceProviderTest, BasicInitializeGLSoftware) { | 2842 TEST(ResourceProviderTest, BasicInitializeGLSoftware) { |
| 2821 scoped_ptr<ContextSharedData> shared_data = ContextSharedData::Create(); | 2843 scoped_ptr<ContextSharedData> shared_data = ContextSharedData::Create(); |
| 2822 FakeOutputSurfaceClient client; | 2844 FakeOutputSurfaceClient client; |
| 2823 scoped_ptr<FakeOutputSurface> output_surface( | 2845 scoped_ptr<FakeOutputSurface> output_surface( |
| 2824 FakeOutputSurface::CreateDeferredGL( | 2846 FakeOutputSurface::CreateDeferredGL( |
| 2825 scoped_ptr<SoftwareOutputDevice>(new SoftwareOutputDevice))); | 2847 scoped_ptr<SoftwareOutputDevice>(new SoftwareOutputDevice))); |
| 2826 EXPECT_TRUE(output_surface->BindToClient(&client)); | 2848 EXPECT_TRUE(output_surface->BindToClient(&client)); |
| 2827 scoped_ptr<ResourceProvider> resource_provider( | 2849 scoped_ptr<ResourceProvider> resource_provider( |
| 2828 ResourceProvider::Create(output_surface.get(), NULL, 0, false)); | 2850 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); |
| 2829 | 2851 |
| 2830 CheckCreateResource(ResourceProvider::Bitmap, resource_provider.get(), NULL); | 2852 CheckCreateResource(ResourceProvider::Bitmap, resource_provider.get(), NULL); |
| 2831 | 2853 |
| 2832 InitializeGLAndCheck(shared_data.get(), | 2854 InitializeGLAndCheck(shared_data.get(), |
| 2833 resource_provider.get(), | 2855 resource_provider.get(), |
| 2834 output_surface.get()); | 2856 output_surface.get()); |
| 2835 | 2857 |
| 2836 resource_provider->InitializeSoftware(); | 2858 resource_provider->InitializeSoftware(); |
| 2837 output_surface->ReleaseGL(); | 2859 output_surface->ReleaseGL(); |
| 2838 CheckCreateResource(ResourceProvider::Bitmap, resource_provider.get(), NULL); | 2860 CheckCreateResource(ResourceProvider::Bitmap, resource_provider.get(), NULL); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2850 new AllocationTrackingContext3D); | 2872 new AllocationTrackingContext3D); |
| 2851 AllocationTrackingContext3D* context = context_owned.get(); | 2873 AllocationTrackingContext3D* context = context_owned.get(); |
| 2852 context_owned->set_support_compressed_texture_etc1(true); | 2874 context_owned->set_support_compressed_texture_etc1(true); |
| 2853 | 2875 |
| 2854 FakeOutputSurfaceClient output_surface_client; | 2876 FakeOutputSurfaceClient output_surface_client; |
| 2855 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( | 2877 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
| 2856 context_owned.PassAs<TestWebGraphicsContext3D>())); | 2878 context_owned.PassAs<TestWebGraphicsContext3D>())); |
| 2857 CHECK(output_surface->BindToClient(&output_surface_client)); | 2879 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 2858 | 2880 |
| 2859 gfx::Size size(4, 4); | 2881 gfx::Size size(4, 4); |
| 2860 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( | 2882 scoped_ptr<ResourceProvider> resource_provider( |
| 2861 output_surface.get(), shared_bitmap_manager_.get(), 0, false)); | 2883 ResourceProvider::Create(output_surface.get(), |
| 2884 shared_bitmap_manager_.get(), |
| 2885 0, |
| 2886 false, |
| 2887 1)); |
| 2862 int texture_id = 123; | 2888 int texture_id = 123; |
| 2863 | 2889 |
| 2864 ResourceProvider::ResourceId id = resource_provider->CreateResource( | 2890 ResourceProvider::ResourceId id = resource_provider->CreateResource( |
| 2865 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, ETC1); | 2891 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, ETC1); |
| 2866 EXPECT_NE(0u, id); | 2892 EXPECT_NE(0u, id); |
| 2867 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id)); | 2893 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); |
| 2868 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); | 2894 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); |
| 2869 resource_provider->AllocateForTesting(id); | 2895 resource_provider->AllocateForTesting(id); |
| 2870 | 2896 |
| 2871 EXPECT_CALL(*context, deleteTexture(texture_id)).Times(1); | 2897 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); |
| 2872 resource_provider->DeleteResource(id); | 2898 resource_provider->DeleteResource(id); |
| 2873 } | 2899 } |
| 2874 | 2900 |
| 2875 TEST_P(ResourceProviderTest, CompressedTextureETC1SetPixels) { | 2901 TEST_P(ResourceProviderTest, CompressedTextureETC1SetPixels) { |
| 2876 if (GetParam() != ResourceProvider::GLTexture) | 2902 if (GetParam() != ResourceProvider::GLTexture) |
| 2877 return; | 2903 return; |
| 2878 | 2904 |
| 2879 scoped_ptr<AllocationTrackingContext3D> context_owned( | 2905 scoped_ptr<AllocationTrackingContext3D> context_owned( |
| 2880 new AllocationTrackingContext3D); | 2906 new AllocationTrackingContext3D); |
| 2881 AllocationTrackingContext3D* context = context_owned.get(); | 2907 AllocationTrackingContext3D* context = context_owned.get(); |
| 2882 context_owned->set_support_compressed_texture_etc1(true); | 2908 context_owned->set_support_compressed_texture_etc1(true); |
| 2883 | 2909 |
| 2884 FakeOutputSurfaceClient output_surface_client; | 2910 FakeOutputSurfaceClient output_surface_client; |
| 2885 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( | 2911 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
| 2886 context_owned.PassAs<TestWebGraphicsContext3D>())); | 2912 context_owned.PassAs<TestWebGraphicsContext3D>())); |
| 2887 CHECK(output_surface->BindToClient(&output_surface_client)); | 2913 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 2888 | 2914 |
| 2889 gfx::Size size(4, 4); | 2915 gfx::Size size(4, 4); |
| 2890 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( | 2916 scoped_ptr<ResourceProvider> resource_provider( |
| 2891 output_surface.get(), shared_bitmap_manager_.get(), 0, false)); | 2917 ResourceProvider::Create(output_surface.get(), |
| 2918 shared_bitmap_manager_.get(), |
| 2919 0, |
| 2920 false, |
| 2921 1)); |
| 2892 int texture_id = 123; | 2922 int texture_id = 123; |
| 2893 uint8_t pixels[8]; | 2923 uint8_t pixels[8]; |
| 2894 | 2924 |
| 2895 ResourceProvider::ResourceId id = resource_provider->CreateResource( | 2925 ResourceProvider::ResourceId id = resource_provider->CreateResource( |
| 2896 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, ETC1); | 2926 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, ETC1); |
| 2897 EXPECT_NE(0u, id); | 2927 EXPECT_NE(0u, id); |
| 2898 EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id)); | 2928 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); |
| 2899 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(3); | 2929 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(3); |
| 2900 EXPECT_CALL(*context, | 2930 EXPECT_CALL(*context, |
| 2901 compressedTexImage2D( | 2931 compressedTexImage2D( |
| 2902 _, 0, _, size.width(), size.height(), _, _, _)).Times(1); | 2932 _, 0, _, size.width(), size.height(), _, _, _)).Times(1); |
| 2903 resource_provider->SetPixels( | 2933 resource_provider->SetPixels( |
| 2904 id, pixels, gfx::Rect(size), gfx::Rect(size), gfx::Vector2d(0, 0)); | 2934 id, pixels, gfx::Rect(size), gfx::Rect(size), gfx::Vector2d(0, 0)); |
| 2905 | 2935 |
| 2906 EXPECT_CALL(*context, deleteTexture(texture_id)).Times(1); | 2936 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); |
| 2907 resource_provider->DeleteResource(id); | 2937 resource_provider->DeleteResource(id); |
| 2908 } | 2938 } |
| 2909 | 2939 |
| 2910 INSTANTIATE_TEST_CASE_P( | 2940 INSTANTIATE_TEST_CASE_P( |
| 2911 ResourceProviderTests, | 2941 ResourceProviderTests, |
| 2912 ResourceProviderTest, | 2942 ResourceProviderTest, |
| 2913 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap)); | 2943 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap)); |
| 2914 | 2944 |
| 2945 class TextureIdAllocationTrackingContext : public TestWebGraphicsContext3D { |
| 2946 public: |
| 2947 virtual WebKit::WebGLId NextTextureId() OVERRIDE { |
| 2948 base::AutoLock lock(namespace_->lock); |
| 2949 return namespace_->next_texture_id++; |
| 2950 } |
| 2951 virtual void RetireTextureId(WebKit::WebGLId) OVERRIDE { |
| 2952 } |
| 2953 WebKit::WebGLId PeekTextureId() { |
| 2954 base::AutoLock lock(namespace_->lock); |
| 2955 return namespace_->next_texture_id; |
| 2956 } |
| 2957 }; |
| 2958 |
| 2959 TEST(ResourceProviderTest, TextureAllocationChunkSize) { |
| 2960 scoped_ptr<TextureIdAllocationTrackingContext> context_owned( |
| 2961 new TextureIdAllocationTrackingContext); |
| 2962 TextureIdAllocationTrackingContext* context = context_owned.get(); |
| 2963 |
| 2964 FakeOutputSurfaceClient output_surface_client; |
| 2965 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
| 2966 context_owned.PassAs<TestWebGraphicsContext3D>())); |
| 2967 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 2968 |
| 2969 gfx::Size size(1, 1); |
| 2970 ResourceFormat format = RGBA_8888; |
| 2971 |
| 2972 { |
| 2973 size_t kTextureAllocationChunkSize = 1; |
| 2974 scoped_ptr<ResourceProvider> resource_provider( |
| 2975 ResourceProvider::Create(output_surface.get(), |
| 2976 NULL, |
| 2977 0, |
| 2978 false, |
| 2979 kTextureAllocationChunkSize)); |
| 2980 |
| 2981 ResourceProvider::ResourceId id = resource_provider->CreateResource( |
| 2982 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
| 2983 resource_provider->AllocateForTesting(id); |
| 2984 Mock::VerifyAndClearExpectations(context); |
| 2985 |
| 2986 DCHECK_EQ(2u, context->PeekTextureId()); |
| 2987 resource_provider->DeleteResource(id); |
| 2988 } |
| 2989 |
| 2990 { |
| 2991 size_t kTextureAllocationChunkSize = 8; |
| 2992 scoped_ptr<ResourceProvider> resource_provider( |
| 2993 ResourceProvider::Create(output_surface.get(), |
| 2994 NULL, |
| 2995 0, |
| 2996 false, |
| 2997 kTextureAllocationChunkSize)); |
| 2998 |
| 2999 ResourceProvider::ResourceId id = resource_provider->CreateResource( |
| 3000 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
| 3001 resource_provider->AllocateForTesting(id); |
| 3002 Mock::VerifyAndClearExpectations(context); |
| 3003 |
| 3004 DCHECK_EQ(10u, context->PeekTextureId()); |
| 3005 resource_provider->DeleteResource(id); |
| 3006 } |
| 3007 } |
| 3008 |
| 2915 } // namespace | 3009 } // namespace |
| 2916 } // namespace cc | 3010 } // namespace cc |
| OLD | NEW |