Chromium Code Reviews| 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/resource_provider.h" | 5 #include "cc/resource_provider.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "cc/output_surface.h" | 8 #include "cc/output_surface.h" |
| 9 #include "cc/scoped_ptr_deque.h" | 9 #include "cc/scoped_ptr_deque.h" |
| 10 #include "cc/scoped_ptr_hash_map.h" | 10 #include "cc/scoped_ptr_hash_map.h" |
| 11 #include "cc/test/compositor_fake_web_graphics_context_3d.h" | 11 #include "cc/test/compositor_fake_web_graphics_context_3d.h" |
| 12 #include "cc/test/fake_output_surface.h" | 12 #include "cc/test/fake_output_surface.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h" | 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h" |
| 16 #include "third_party/khronos/GLES2/gl2.h" | 16 #include "third_party/khronos/GLES2/gl2.h" |
| 17 #include "third_party/khronos/GLES2/gl2ext.h" | 17 #include "third_party/khronos/GLES2/gl2ext.h" |
| 18 #include "ui/gfx/rect.h" | 18 #include "ui/gfx/rect.h" |
| 19 | 19 |
| 20 using namespace WebKit; | 20 using namespace WebKit; |
| 21 | 21 |
| 22 using testing::Mock; | 22 using testing::Mock; |
| 23 using testing::StrictMock; | |
| 24 using testing::NiceMock; | |
| 25 using testing::_; | |
| 23 | 26 |
| 24 namespace cc { | 27 namespace cc { |
| 25 namespace { | 28 namespace { |
| 26 | 29 |
| 27 size_t textureSize(const gfx::Size& size, WGC3Denum format) | 30 size_t textureSize(const gfx::Size& size, WGC3Denum format) |
| 28 { | 31 { |
| 29 unsigned int componentsPerPixel = 4; | 32 unsigned int componentsPerPixel = 4; |
| 30 unsigned int bytesPerComponent = 1; | 33 unsigned int bytesPerComponent = 1; |
| 31 return size.width() * size.height() * componentsPerPixel * bytesPerComponent ; | 34 return size.width() * size.height() * componentsPerPixel * bytesPerComponent ; |
| 32 } | 35 } |
| (...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 633 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL _LINEAR)); | 636 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL _LINEAR)); |
| 634 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL _LINEAR)); | 637 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL _LINEAR)); |
| 635 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLA MP_TO_EDGE)); | 638 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLA MP_TO_EDGE)); |
| 636 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLA MP_TO_EDGE)); | 639 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLA MP_TO_EDGE)); |
| 637 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_POOL_CHROMIUM, GL_TEXTURE_POOL_MANAGED_CHROMIUM)); | 640 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_POOL_CHROMIUM, GL_TEXTURE_POOL_MANAGED_CHROMIUM)); |
| 638 ResourceProvider::ResourceId id = resourceProvider->createManagedResource(si ze, format, ResourceProvider::TextureUsageAny); | 641 ResourceProvider::ResourceId id = resourceProvider->createManagedResource(si ze, format, ResourceProvider::TextureUsageAny); |
| 639 | 642 |
| 640 Mock::VerifyAndClearExpectations(context); | 643 Mock::VerifyAndClearExpectations(context); |
| 641 } | 644 } |
| 642 | 645 |
| 646 class AllocationTrackingContext3D : public FakeWebGraphicsContext3D { | |
| 647 public: | |
| 648 MOCK_METHOD9(texImage2D, void(WGC3Denum target, WGC3Dint level, WGC3Denum in ternalformat, | |
| 649 WGC3Dsizei width, WGC3Dsizei height, WGC3Dint border, WGC3Denum format, | |
| 650 WGC3Denum type, const void* pixels)); | |
| 651 MOCK_METHOD9(texSubImage2D, void(WGC3Denum target, WGC3Dint level, WGC3Dint xoffset, WGC3Dint yoffset, | |
| 652 WGC3Dsizei width, WGC3Dsizei height, WGC3De num format, | |
| 653 WGC3Denum type, const void* pixels)); | |
| 654 MOCK_METHOD9(asyncTexImage2DCHROMIUM, void(WGC3Denum target, WGC3Dint level, WGC3Denum internalformat, | |
| 655 WGC3Dsizei width, WGC3Dsizei heigh t, WGC3Dint border, WGC3Denum format, | |
| 656 WGC3Denum type, const void* pixels )); | |
| 657 MOCK_METHOD9(asyncTexSubImage2DCHROMIUM, void(WGC3Denum target, WGC3Dint lev el, WGC3Dint xoffset, WGC3Dint yoffset, | |
| 658 WGC3Dsizei width, WGC3Dsizei h eight, WGC3Denum format, | |
| 659 WGC3Denum type, const void* pi xels)); | |
| 660 }; | |
| 661 | |
| 662 TEST_P(ResourceProviderTest, TextureAllocation) | |
| 663 { | |
| 664 // Only for GL textures. | |
| 665 if (GetParam() != ResourceProvider::GLTexture) | |
| 666 return; | |
| 667 scoped_ptr<OutputSurface> outputSurface( | |
| 668 FakeOutputSurface::Create3d( | |
| 669 scoped_ptr<WebKit::WebGraphicsContext3D>( | |
| 670 static_cast<WebKit::WebGraphicsContext3D*>( | |
| 671 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.
| |
| 672 gfx::Size size(2, 2); | |
| 673 gfx::Vector2d offset(0, 0); | |
| 674 gfx::Rect rect(0, 0, 2, 2); | |
| 675 WGC3Denum format = GL_RGBA; | |
| 676 ResourceProvider::ResourceId id = 0; | |
| 677 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
| |
| 678 | |
| 679 AllocationTrackingContext3D* context = static_cast<AllocationTrackingContext 3D*>(outputSurface->Context3D()); | |
| 680 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu tSurface.get())); | |
| 681 | |
| 682 // Lazy allocation. Don't allocate when creating the resource. | |
| 683 EXPECT_CALL(*context, texImage2D(_,_,_,_,_,_,_,_,_)).Times(0); | |
| 684 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_,_,_,_,_,_,_,_,_)).Times(0); | |
| 685 id = resourceProvider->createResource(size, format, ResourceProvider::Textur eUsageAny); | |
| 686 resourceProvider->deleteResource(id); | |
| 687 Mock::VerifyAndClearExpectations(context); | |
| 688 | |
| 689 // Do allocate when we set the pixels. | |
| 690 EXPECT_CALL(*context, texImage2D(_,_,_,2,2,_,_,_,_)).Times(1); | |
| 691 EXPECT_CALL(*context, texSubImage2D(_,_,_,_,2,2,_,_,_)).Times(1); | |
| 692 id = resourceProvider->createResource(size, format, ResourceProvider::Textur eUsageAny); | |
| 693 resourceProvider->setPixels(id, pixels, rect, rect, offset); | |
| 694 resourceProvider->deleteResource(id); | |
| 695 Mock::VerifyAndClearExpectations(context); | |
| 696 | |
| 697 // Same for setPixelsFromBuffer | |
| 698 EXPECT_CALL(*context, texImage2D(_,_,_,2,2,_,_,_,_)).Times(1); | |
| 699 EXPECT_CALL(*context, texSubImage2D(_,_,_,_,2,2,_,_,_)).Times(1); | |
| 700 id = resourceProvider->createResource(size, format, ResourceProvider::Textur eUsageAny); | |
| 701 resourceProvider->acquirePixelBuffer(id); | |
| 702 resourceProvider->setPixelsFromBuffer(id); | |
| 703 resourceProvider->releasePixelBuffer(id); | |
| 704 resourceProvider->deleteResource(id); | |
| 705 Mock::VerifyAndClearExpectations(context); | |
| 706 | |
| 707 // Same for async version. | |
| 708 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_,_,_,2,2,_,_,_,_)).Times(1); | |
| 709 id = resourceProvider->createResource(size, format, ResourceProvider::Textur eUsageAny); | |
| 710 resourceProvider->acquirePixelBuffer(id); | |
| 711 resourceProvider->beginSetPixels(id); | |
| 712 resourceProvider->releasePixelBuffer(id); | |
| 713 resourceProvider->deleteResource(id); | |
| 714 Mock::VerifyAndClearExpectations(context); | |
| 715 } | |
| 716 | |
| 717 | |
|
piman
2012/12/18 04:12:34
nit: 2 superfluous blank lines.
| |
| 718 | |
| 643 INSTANTIATE_TEST_CASE_P(ResourceProviderTests, | 719 INSTANTIATE_TEST_CASE_P(ResourceProviderTests, |
| 644 ResourceProviderTest, | 720 ResourceProviderTest, |
| 645 ::testing::Values(ResourceProvider::GLTexture, | 721 ::testing::Values(ResourceProvider::GLTexture, |
| 646 ResourceProvider::Bitmap)); | 722 ResourceProvider::Bitmap)); |
| 647 | 723 |
| 648 } // namespace | 724 } // namespace |
| 649 } // namespace cc | 725 } // namespace cc |
| OLD | NEW |