| 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/fake_output_surface.h" | 11 #include "cc/test/fake_output_surface.h" |
| 12 #include "cc/test/fake_web_graphics_context_3d.h" | 12 #include "cc/test/fake_web_graphics_context_3d.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::_; | |
| 26 | 23 |
| 27 namespace cc { | 24 namespace cc { |
| 28 namespace { | 25 namespace { |
| 29 | 26 |
| 30 size_t textureSize(const gfx::Size& size, WGC3Denum format) | 27 size_t textureSize(const gfx::Size& size, WGC3Denum format) |
| 31 { | 28 { |
| 32 unsigned int componentsPerPixel = 4; | 29 unsigned int componentsPerPixel = 4; |
| 33 unsigned int bytesPerComponent = 1; | 30 unsigned int bytesPerComponent = 1; |
| 34 return size.width() * size.height() * componentsPerPixel * bytesPerComponent
; | 31 return size.width() * size.height() * componentsPerPixel * bytesPerComponent
; |
| 35 } | 32 } |
| (...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 int textureId = 1; | 580 int textureId = 1; |
| 584 | 581 |
| 585 // Check that the texture gets created with the right sampler settings. | 582 // Check that the texture gets created with the right sampler settings. |
| 586 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, textureId)); | 583 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, textureId)); |
| 587 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL
_LINEAR)); | 584 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL
_LINEAR)); |
| 588 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL
_LINEAR)); | 585 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL
_LINEAR)); |
| 589 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLA
MP_TO_EDGE)); | 586 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLA
MP_TO_EDGE)); |
| 590 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLA
MP_TO_EDGE)); | 587 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLA
MP_TO_EDGE)); |
| 591 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_POOL_CHROMIUM,
GL_TEXTURE_POOL_UNMANAGED_CHROMIUM)); | 588 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_POOL_CHROMIUM,
GL_TEXTURE_POOL_UNMANAGED_CHROMIUM)); |
| 592 ResourceProvider::ResourceId id = resourceProvider->createResource(size, for
mat, ResourceProvider::TextureUsageAny); | 589 ResourceProvider::ResourceId id = resourceProvider->createResource(size, for
mat, ResourceProvider::TextureUsageAny); |
| 593 resourceProvider->allocateForTesting(id); | |
| 594 | 590 |
| 595 // Creating a sampler with the default filter should not change any texture | 591 // Creating a sampler with the default filter should not change any texture |
| 596 // parameters. | 592 // parameters. |
| 597 { | 593 { |
| 598 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, textureId)); | 594 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, textureId)); |
| 599 ResourceProvider::ScopedSamplerGL sampler(resourceProvider.get(), id, GL
_TEXTURE_2D, GL_LINEAR); | 595 ResourceProvider::ScopedSamplerGL sampler(resourceProvider.get(), id, GL
_TEXTURE_2D, GL_LINEAR); |
| 600 } | 596 } |
| 601 | 597 |
| 602 // Using a different filter should be reflected in the texture parameters. | 598 // Using a different filter should be reflected in the texture parameters. |
| 603 { | 599 { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL
_LINEAR)); | 633 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL
_LINEAR)); |
| 638 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL
_LINEAR)); | 634 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL
_LINEAR)); |
| 639 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLA
MP_TO_EDGE)); | 635 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLA
MP_TO_EDGE)); |
| 640 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLA
MP_TO_EDGE)); | 636 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLA
MP_TO_EDGE)); |
| 641 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_POOL_CHROMIUM,
GL_TEXTURE_POOL_MANAGED_CHROMIUM)); | 637 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_POOL_CHROMIUM,
GL_TEXTURE_POOL_MANAGED_CHROMIUM)); |
| 642 ResourceProvider::ResourceId id = resourceProvider->createManagedResource(si
ze, format, ResourceProvider::TextureUsageAny); | 638 ResourceProvider::ResourceId id = resourceProvider->createManagedResource(si
ze, format, ResourceProvider::TextureUsageAny); |
| 643 | 639 |
| 644 Mock::VerifyAndClearExpectations(context); | 640 Mock::VerifyAndClearExpectations(context); |
| 645 } | 641 } |
| 646 | 642 |
| 647 class AllocationTrackingContext3D : public FakeWebGraphicsContext3D { | |
| 648 public: | |
| 649 MOCK_METHOD9(texImage2D, void(WGC3Denum target, WGC3Dint level, WGC3Denum in
ternalformat, | |
| 650 WGC3Dsizei width, WGC3Dsizei height, WGC3Dint
border, WGC3Denum format, | |
| 651 WGC3Denum type, const void* pixels)); | |
| 652 MOCK_METHOD9(texSubImage2D, void(WGC3Denum target, WGC3Dint level, WGC3Dint
xoffset, WGC3Dint yoffset, | |
| 653 WGC3Dsizei width, WGC3Dsizei height, WGC3De
num format, | |
| 654 WGC3Denum type, const void* pixels)); | |
| 655 MOCK_METHOD9(asyncTexImage2DCHROMIUM, void(WGC3Denum target, WGC3Dint level,
WGC3Denum internalformat, | |
| 656 WGC3Dsizei width, WGC3Dsizei heigh
t, WGC3Dint border, WGC3Denum format, | |
| 657 WGC3Denum type, const void* pixels
)); | |
| 658 MOCK_METHOD9(asyncTexSubImage2DCHROMIUM, void(WGC3Denum target, WGC3Dint lev
el, WGC3Dint xoffset, WGC3Dint yoffset, | |
| 659 WGC3Dsizei width, WGC3Dsizei h
eight, WGC3Denum format, | |
| 660 WGC3Denum type, const void* pi
xels)); | |
| 661 }; | |
| 662 | |
| 663 TEST_P(ResourceProviderTest, TextureAllocation) | |
| 664 { | |
| 665 // Only for GL textures. | |
| 666 if (GetParam() != ResourceProvider::GLTexture) | |
| 667 return; | |
| 668 scoped_ptr<WebKit::WebGraphicsContext3D> mock_context( | |
| 669 static_cast<WebKit::WebGraphicsContext3D*>(new NiceMock<AllocationTracki
ngContext3D>)); | |
| 670 scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(mock_con
text.Pass())); | |
| 671 | |
| 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] = {0}; | |
| 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 INSTANTIATE_TEST_CASE_P(ResourceProviderTests, | 643 INSTANTIATE_TEST_CASE_P(ResourceProviderTests, |
| 718 ResourceProviderTest, | 644 ResourceProviderTest, |
| 719 ::testing::Values(ResourceProvider::GLTexture, | 645 ::testing::Values(ResourceProvider::GLTexture, |
| 720 ResourceProvider::Bitmap)); | 646 ResourceProvider::Bitmap)); |
| 721 | 647 |
| 722 } // namespace | 648 } // namespace |
| 723 } // namespace cc | 649 } // namespace cc |
| OLD | NEW |