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 2383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2394 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); | 2394 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); |
2395 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); | 2395 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); |
2396 } | 2396 } |
2397 } | 2397 } |
2398 | 2398 |
2399 class AllocationTrackingContext3D : public TestWebGraphicsContext3D { | 2399 class AllocationTrackingContext3D : public TestWebGraphicsContext3D { |
2400 public: | 2400 public: |
2401 MOCK_METHOD0(NextTextureId, WebGLId()); | 2401 MOCK_METHOD0(NextTextureId, WebGLId()); |
2402 MOCK_METHOD1(RetireTextureId, void(WebGLId id)); | 2402 MOCK_METHOD1(RetireTextureId, void(WebGLId id)); |
2403 MOCK_METHOD2(bindTexture, void(WGC3Denum target, WebGLId texture)); | 2403 MOCK_METHOD2(bindTexture, void(WGC3Denum target, WebGLId texture)); |
| 2404 MOCK_METHOD5(texStorage2DEXT, |
| 2405 void(WGC3Denum target, |
| 2406 WGC3Dint levels, |
| 2407 WGC3Duint internalformat, |
| 2408 WGC3Dint width, |
| 2409 WGC3Dint height)); |
2404 MOCK_METHOD9(texImage2D, | 2410 MOCK_METHOD9(texImage2D, |
2405 void(WGC3Denum target, | 2411 void(WGC3Denum target, |
2406 WGC3Dint level, | 2412 WGC3Dint level, |
2407 WGC3Denum internalformat, | 2413 WGC3Denum internalformat, |
2408 WGC3Dsizei width, | 2414 WGC3Dsizei width, |
2409 WGC3Dsizei height, | 2415 WGC3Dsizei height, |
2410 WGC3Dint border, | 2416 WGC3Dint border, |
2411 WGC3Denum format, | 2417 WGC3Denum format, |
2412 WGC3Denum type, | 2418 WGC3Denum type, |
2413 const void* pixels)); | 2419 const void* pixels)); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2527 ASSERT_TRUE(resource_provider->DidSetPixelsComplete(id)); | 2533 ASSERT_TRUE(resource_provider->DidSetPixelsComplete(id)); |
2528 | 2534 |
2529 resource_provider->ReleasePixelBuffer(id); | 2535 resource_provider->ReleasePixelBuffer(id); |
2530 | 2536 |
2531 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); | 2537 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); |
2532 resource_provider->DeleteResource(id); | 2538 resource_provider->DeleteResource(id); |
2533 | 2539 |
2534 Mock::VerifyAndClearExpectations(context); | 2540 Mock::VerifyAndClearExpectations(context); |
2535 } | 2541 } |
2536 | 2542 |
| 2543 TEST_P(ResourceProviderTest, TextureAllocationStorageUsageAny) { |
| 2544 // Only for GL textures. |
| 2545 if (GetParam() != ResourceProvider::GLTexture) |
| 2546 return; |
| 2547 scoped_ptr<AllocationTrackingContext3D> context_owned( |
| 2548 new StrictMock<AllocationTrackingContext3D>); |
| 2549 AllocationTrackingContext3D* context = context_owned.get(); |
| 2550 context->set_support_texture_storage(true); |
| 2551 |
| 2552 FakeOutputSurfaceClient output_surface_client; |
| 2553 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
| 2554 context_owned.PassAs<TestWebGraphicsContext3D>())); |
| 2555 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 2556 |
| 2557 scoped_ptr<ResourceProvider> resource_provider( |
| 2558 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); |
| 2559 |
| 2560 gfx::Size size(2, 2); |
| 2561 ResourceFormat format = RGBA_8888; |
| 2562 ResourceProvider::ResourceId id = 0; |
| 2563 int texture_id = 123; |
| 2564 |
| 2565 // Lazy allocation. Don't allocate when creating the resource. |
| 2566 id = resource_provider->CreateResource( |
| 2567 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
| 2568 |
| 2569 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); |
| 2570 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); |
| 2571 EXPECT_CALL(*context, texStorage2DEXT(_, _, _, 2, 2)).Times(1); |
| 2572 resource_provider->AllocateForTesting(id); |
| 2573 |
| 2574 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); |
| 2575 resource_provider->DeleteResource(id); |
| 2576 |
| 2577 Mock::VerifyAndClearExpectations(context); |
| 2578 } |
| 2579 |
| 2580 TEST_P(ResourceProviderTest, TextureAllocationStorageUsageFramebuffer) { |
| 2581 // Only for GL textures. |
| 2582 if (GetParam() != ResourceProvider::GLTexture) |
| 2583 return; |
| 2584 scoped_ptr<AllocationTrackingContext3D> context_owned( |
| 2585 new StrictMock<AllocationTrackingContext3D>); |
| 2586 AllocationTrackingContext3D* context = context_owned.get(); |
| 2587 context->set_support_texture_storage(true); |
| 2588 |
| 2589 FakeOutputSurfaceClient output_surface_client; |
| 2590 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
| 2591 context_owned.PassAs<TestWebGraphicsContext3D>())); |
| 2592 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 2593 |
| 2594 scoped_ptr<ResourceProvider> resource_provider( |
| 2595 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); |
| 2596 |
| 2597 gfx::Size size(2, 2); |
| 2598 ResourceFormat format = RGBA_8888; |
| 2599 ResourceProvider::ResourceId id = 0; |
| 2600 int texture_id = 123; |
| 2601 |
| 2602 // Lazy allocation. Don't allocate when creating the resource. |
| 2603 id = resource_provider->CreateResource( |
| 2604 size, |
| 2605 GL_CLAMP_TO_EDGE, |
| 2606 ResourceProvider::TextureUsageFramebuffer, |
| 2607 format); |
| 2608 |
| 2609 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); |
| 2610 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); |
| 2611 EXPECT_CALL(*context, texImage2D(_, _, _, 2, 2, _, _, _, _)).Times(1); |
| 2612 resource_provider->AllocateForTesting(id); |
| 2613 |
| 2614 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); |
| 2615 resource_provider->DeleteResource(id); |
| 2616 |
| 2617 Mock::VerifyAndClearExpectations(context); |
| 2618 } |
| 2619 |
2537 TEST_P(ResourceProviderTest, PixelBuffer_GLTexture) { | 2620 TEST_P(ResourceProviderTest, PixelBuffer_GLTexture) { |
2538 if (GetParam() != ResourceProvider::GLTexture) | 2621 if (GetParam() != ResourceProvider::GLTexture) |
2539 return; | 2622 return; |
2540 scoped_ptr<AllocationTrackingContext3D> context_owned( | 2623 scoped_ptr<AllocationTrackingContext3D> context_owned( |
2541 new StrictMock<AllocationTrackingContext3D>); | 2624 new StrictMock<AllocationTrackingContext3D>); |
2542 AllocationTrackingContext3D* context = context_owned.get(); | 2625 AllocationTrackingContext3D* context = context_owned.get(); |
2543 | 2626 |
2544 FakeOutputSurfaceClient output_surface_client; | 2627 FakeOutputSurfaceClient output_surface_client; |
2545 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( | 2628 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
2546 context_owned.PassAs<TestWebGraphicsContext3D>())); | 2629 context_owned.PassAs<TestWebGraphicsContext3D>())); |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3011 resource_provider->AllocateForTesting(id); | 3094 resource_provider->AllocateForTesting(id); |
3012 Mock::VerifyAndClearExpectations(context); | 3095 Mock::VerifyAndClearExpectations(context); |
3013 | 3096 |
3014 DCHECK_EQ(10u, context->PeekTextureId()); | 3097 DCHECK_EQ(10u, context->PeekTextureId()); |
3015 resource_provider->DeleteResource(id); | 3098 resource_provider->DeleteResource(id); |
3016 } | 3099 } |
3017 } | 3100 } |
3018 | 3101 |
3019 } // namespace | 3102 } // namespace |
3020 } // namespace cc | 3103 } // namespace cc |
OLD | NEW |