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

Side by Side Diff: cc/resources/resource_provider_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698