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

Unified Diff: cc/resource_provider_unittest.cc

Issue 11622008: cc: Defer texture allocation (to allow async allocations). (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Address feedback. Add test. Created 8 years 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 side-by-side diff with in-line comments
Download patch
« cc/resource_provider.cc ('K') | « cc/resource_provider.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/resource_provider_unittest.cc
diff --git a/cc/resource_provider_unittest.cc b/cc/resource_provider_unittest.cc
index aee55ba8a68d588fb09aef006a5f3000e3a30a17..8ed7fd1c0d08ca9078e855d176010ecdf019af8f 100644
--- a/cc/resource_provider_unittest.cc
+++ b/cc/resource_provider_unittest.cc
@@ -20,6 +20,9 @@
using namespace WebKit;
using testing::Mock;
+using testing::StrictMock;
+using testing::NiceMock;
+using testing::_;
namespace cc {
namespace {
@@ -640,6 +643,79 @@ TEST_P(ResourceProviderTest, ManagedResource)
Mock::VerifyAndClearExpectations(context);
}
+class AllocationTrackingContext3D : public FakeWebGraphicsContext3D {
+public:
+ MOCK_METHOD9(texImage2D, void(WGC3Denum target, WGC3Dint level, WGC3Denum internalformat,
+ WGC3Dsizei width, WGC3Dsizei height, WGC3Dint border, WGC3Denum format,
+ WGC3Denum type, const void* pixels));
+ MOCK_METHOD9(texSubImage2D, void(WGC3Denum target, WGC3Dint level, WGC3Dint xoffset, WGC3Dint yoffset,
+ WGC3Dsizei width, WGC3Dsizei height, WGC3Denum format,
+ WGC3Denum type, const void* pixels));
+ MOCK_METHOD9(asyncTexImage2DCHROMIUM, void(WGC3Denum target, WGC3Dint level, WGC3Denum internalformat,
+ WGC3Dsizei width, WGC3Dsizei height, WGC3Dint border, WGC3Denum format,
+ WGC3Denum type, const void* pixels));
+ MOCK_METHOD9(asyncTexSubImage2DCHROMIUM, void(WGC3Denum target, WGC3Dint level, WGC3Dint xoffset, WGC3Dint yoffset,
+ WGC3Dsizei width, WGC3Dsizei height, WGC3Denum format,
+ WGC3Denum type, const void* pixels));
+};
+
+TEST_P(ResourceProviderTest, TextureAllocation)
+{
+ // Only for GL textures.
+ if (GetParam() != ResourceProvider::GLTexture)
+ return;
+ scoped_ptr<OutputSurface> outputSurface(
+ FakeOutputSurface::Create3d(
+ scoped_ptr<WebKit::WebGraphicsContext3D>(
+ static_cast<WebKit::WebGraphicsContext3D*>(
+ new NiceMock<AllocationTrackingContext3D>))));
piman 2012/12/18 04:12:34 nit: mind breaking this into 2 statements for inde
epenner 2012/12/18 04:23:52 Done.
+ gfx::Size size(2, 2);
+ gfx::Vector2d offset(0, 0);
+ gfx::Rect rect(0, 0, 2, 2);
+ WGC3Denum format = GL_RGBA;
+ ResourceProvider::ResourceId id = 0;
+ uint8_t pixels[16];
piman 2012/12/18 04:12:34 nit: initialize! You can do = {0};
epenner 2012/12/18 04:23:52 Wasn't used, but good point. Also, I didn't know a
piman 2012/12/18 04:36:02 Just FYI, it's used below in resourceProvider->set
+
+ AllocationTrackingContext3D* context = static_cast<AllocationTrackingContext3D*>(outputSurface->Context3D());
+ scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outputSurface.get()));
+
+ // Lazy allocation. Don't allocate when creating the resource.
+ EXPECT_CALL(*context, texImage2D(_,_,_,_,_,_,_,_,_)).Times(0);
+ EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_,_,_,_,_,_,_,_,_)).Times(0);
+ id = resourceProvider->createResource(size, format, ResourceProvider::TextureUsageAny);
+ resourceProvider->deleteResource(id);
+ Mock::VerifyAndClearExpectations(context);
+
+ // Do allocate when we set the pixels.
+ EXPECT_CALL(*context, texImage2D(_,_,_,2,2,_,_,_,_)).Times(1);
+ EXPECT_CALL(*context, texSubImage2D(_,_,_,_,2,2,_,_,_)).Times(1);
+ id = resourceProvider->createResource(size, format, ResourceProvider::TextureUsageAny);
+ resourceProvider->setPixels(id, pixels, rect, rect, offset);
+ resourceProvider->deleteResource(id);
+ Mock::VerifyAndClearExpectations(context);
+
+ // Same for setPixelsFromBuffer
+ EXPECT_CALL(*context, texImage2D(_,_,_,2,2,_,_,_,_)).Times(1);
+ EXPECT_CALL(*context, texSubImage2D(_,_,_,_,2,2,_,_,_)).Times(1);
+ id = resourceProvider->createResource(size, format, ResourceProvider::TextureUsageAny);
+ resourceProvider->acquirePixelBuffer(id);
+ resourceProvider->setPixelsFromBuffer(id);
+ resourceProvider->releasePixelBuffer(id);
+ resourceProvider->deleteResource(id);
+ Mock::VerifyAndClearExpectations(context);
+
+ // Same for async version.
+ EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_,_,_,2,2,_,_,_,_)).Times(1);
+ id = resourceProvider->createResource(size, format, ResourceProvider::TextureUsageAny);
+ resourceProvider->acquirePixelBuffer(id);
+ resourceProvider->beginSetPixels(id);
+ resourceProvider->releasePixelBuffer(id);
+ resourceProvider->deleteResource(id);
+ Mock::VerifyAndClearExpectations(context);
+}
+
+
piman 2012/12/18 04:12:34 nit: 2 superfluous blank lines.
+
INSTANTIATE_TEST_CASE_P(ResourceProviderTests,
ResourceProviderTest,
::testing::Values(ResourceProvider::GLTexture,
« cc/resource_provider.cc ('K') | « cc/resource_provider.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698