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/graphics_context.h" | 8 #include "cc/graphics_context.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_web_compositor_output_surface.h" | 12 #include "cc/test/fake_web_compositor_output_surface.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "third_party/khronos/GLES2/gl2.h" | 15 #include "third_party/khronos/GLES2/gl2.h" |
15 #include "third_party/khronos/GLES2/gl2ext.h" | 16 #include "third_party/khronos/GLES2/gl2ext.h" |
16 #include "ui/gfx/rect.h" | 17 #include "ui/gfx/rect.h" |
17 #include <public/WebGraphicsContext3D.h> | 18 #include <public/WebGraphicsContext3D.h> |
18 | 19 |
19 using namespace WebKit; | 20 using namespace WebKit; |
20 | 21 |
| 22 using testing::Mock; |
| 23 |
21 namespace cc { | 24 namespace cc { |
22 namespace { | 25 namespace { |
23 | 26 |
24 size_t textureSize(const gfx::Size& size, WGC3Denum format) | 27 size_t textureSize(const gfx::Size& size, WGC3Denum format) |
25 { | 28 { |
26 unsigned int componentsPerPixel = 4; | 29 unsigned int componentsPerPixel = 4; |
27 unsigned int bytesPerComponent = 1; | 30 unsigned int bytesPerComponent = 1; |
28 return size.width() * size.height() * componentsPerPixel * bytesPerComponent
; | 31 return size.width() * size.height() * componentsPerPixel * bytesPerComponent
; |
29 } | 32 } |
30 | 33 |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 resourceIdsToTransfer.push_back(mappedId); | 576 resourceIdsToTransfer.push_back(mappedId); |
574 TransferableResourceList list; | 577 TransferableResourceList list; |
575 m_resourceProvider->prepareSendToChild(childId, resourceIdsToTransfer, &
list); | 578 m_resourceProvider->prepareSendToChild(childId, resourceIdsToTransfer, &
list); |
576 EXPECT_NE(0u, list.sync_point); | 579 EXPECT_NE(0u, list.sync_point); |
577 EXPECT_EQ(1u, list.resources.size()); | 580 EXPECT_EQ(1u, list.resources.size()); |
578 childResourceProvider->receiveFromParent(list); | 581 childResourceProvider->receiveFromParent(list); |
579 } | 582 } |
580 EXPECT_EQ(0u, childResourceProvider->numResources()); | 583 EXPECT_EQ(0u, childResourceProvider->numResources()); |
581 } | 584 } |
582 | 585 |
| 586 class TextureStateTrackingContext : public FakeWebGraphicsContext3D { |
| 587 public: |
| 588 MOCK_METHOD2(bindTexture, void(WGC3Denum target, WebGLId texture)); |
| 589 MOCK_METHOD3(texParameteri, void(WGC3Denum target, WGC3Denum pname, WGC3Dint
param)); |
| 590 }; |
| 591 |
| 592 TEST_P(ResourceProviderTest, ScopedSampler) |
| 593 { |
| 594 // Sampling is only supported for GL textures. |
| 595 if (GetParam() != ResourceProvider::GLTexture) |
| 596 return; |
| 597 |
| 598 scoped_ptr<GraphicsContext> outputSurface(FakeWebCompositorOutputSurface::cr
eate(scoped_ptr<WebKit::WebGraphicsContext3D>(new TextureStateTrackingContext)))
; |
| 599 TextureStateTrackingContext* context = static_cast<TextureStateTrackingConte
xt*>(outputSurface->context3D()); |
| 600 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu
tSurface.get())); |
| 601 |
| 602 gfx::Size size(1, 1); |
| 603 WGC3Denum format = GL_RGBA; |
| 604 int pool = 1; |
| 605 int textureId = 1; |
| 606 |
| 607 // Check that the texture gets created with the right sampler settings. |
| 608 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, textureId)); |
| 609 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL
_LINEAR)); |
| 610 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL
_LINEAR)); |
| 611 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLA
MP_TO_EDGE)); |
| 612 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLA
MP_TO_EDGE)); |
| 613 ResourceProvider::ResourceId id = resourceProvider->createResource(pool, siz
e, format, ResourceProvider::TextureUsageAny); |
| 614 |
| 615 // Creating a sampler with the default filter should not change any texture |
| 616 // parameters. |
| 617 { |
| 618 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, textureId)); |
| 619 ResourceProvider::ScopedSamplerGL sampler(resourceProvider.get(), id, GL
_TEXTURE_2D, GL_LINEAR); |
| 620 } |
| 621 |
| 622 // Using a different filter should be reflected in the texture parameters. |
| 623 { |
| 624 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, textureId)); |
| 625 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER
, GL_NEAREST)); |
| 626 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER
, GL_NEAREST)); |
| 627 ResourceProvider::ScopedSamplerGL sampler(resourceProvider.get(), id, GL
_TEXTURE_2D, GL_NEAREST); |
| 628 } |
| 629 |
| 630 // Test resetting to the default filter. |
| 631 { |
| 632 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, textureId)); |
| 633 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)); |
| 635 ResourceProvider::ScopedSamplerGL sampler(resourceProvider.get(), id, GL
_TEXTURE_2D, GL_LINEAR); |
| 636 } |
| 637 |
| 638 Mock::VerifyAndClearExpectations(context); |
| 639 } |
| 640 |
583 INSTANTIATE_TEST_CASE_P(ResourceProviderTests, | 641 INSTANTIATE_TEST_CASE_P(ResourceProviderTests, |
584 ResourceProviderTest, | 642 ResourceProviderTest, |
585 ::testing::Values(ResourceProvider::GLTexture, | 643 ::testing::Values(ResourceProvider::GLTexture, |
586 ResourceProvider::Bitmap)); | 644 ResourceProvider::Bitmap)); |
587 | 645 |
588 } // namespace | 646 } // namespace |
589 } // namespace cc | 647 } // namespace cc |
OLD | NEW |