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 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 int textureId = 1; | 583 int textureId = 1; |
581 | 584 |
582 // Check that the texture gets created with the right sampler settings. | 585 // Check that the texture gets created with the right sampler settings. |
583 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, textureId)); | 586 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, textureId)); |
584 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL
_LINEAR)); | 587 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL
_LINEAR)); |
585 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL
_LINEAR)); | 588 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL
_LINEAR)); |
586 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLA
MP_TO_EDGE)); | 589 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLA
MP_TO_EDGE)); |
587 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLA
MP_TO_EDGE)); | 590 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLA
MP_TO_EDGE)); |
588 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_POOL_CHROMIUM,
GL_TEXTURE_POOL_UNMANAGED_CHROMIUM)); | 591 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_POOL_CHROMIUM,
GL_TEXTURE_POOL_UNMANAGED_CHROMIUM)); |
589 ResourceProvider::ResourceId id = resourceProvider->createResource(size, for
mat, ResourceProvider::TextureUsageAny); | 592 ResourceProvider::ResourceId id = resourceProvider->createResource(size, for
mat, ResourceProvider::TextureUsageAny); |
| 593 resourceProvider->allocateForTesting(id); |
590 | 594 |
591 // Creating a sampler with the default filter should not change any texture | 595 // Creating a sampler with the default filter should not change any texture |
592 // parameters. | 596 // parameters. |
593 { | 597 { |
594 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, textureId)); | 598 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, textureId)); |
595 ResourceProvider::ScopedSamplerGL sampler(resourceProvider.get(), id, GL
_TEXTURE_2D, GL_LINEAR); | 599 ResourceProvider::ScopedSamplerGL sampler(resourceProvider.get(), id, GL
_TEXTURE_2D, GL_LINEAR); |
596 } | 600 } |
597 | 601 |
598 // Using a different filter should be reflected in the texture parameters. | 602 // Using a different filter should be reflected in the texture parameters. |
599 { | 603 { |
(...skipping 33 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)); | 637 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)); | 638 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)); | 639 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)); | 640 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)); | 641 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); | 642 ResourceProvider::ResourceId id = resourceProvider->createManagedResource(si
ze, format, ResourceProvider::TextureUsageAny); |
639 | 643 |
640 Mock::VerifyAndClearExpectations(context); | 644 Mock::VerifyAndClearExpectations(context); |
641 } | 645 } |
642 | 646 |
| 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 |
643 INSTANTIATE_TEST_CASE_P(ResourceProviderTests, | 717 INSTANTIATE_TEST_CASE_P(ResourceProviderTests, |
644 ResourceProviderTest, | 718 ResourceProviderTest, |
645 ::testing::Values(ResourceProvider::GLTexture, | 719 ::testing::Values(ResourceProvider::GLTexture, |
646 ResourceProvider::Bitmap)); | 720 ResourceProvider::Bitmap)); |
647 | 721 |
648 } // namespace | 722 } // namespace |
649 } // namespace cc | 723 } // namespace cc |
OLD | NEW |