| 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/test_web_graphics_context_3d.h" |
| 13 #include "gpu/GLES2/gl2extchromium.h" | 13 #include "gpu/GLES2/gl2extchromium.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" | 16 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" |
| 17 #include "third_party/khronos/GLES2/gl2.h" | 17 #include "third_party/khronos/GLES2/gl2.h" |
| 18 #include "third_party/khronos/GLES2/gl2ext.h" | 18 #include "third_party/khronos/GLES2/gl2ext.h" |
| 19 #include "ui/gfx/rect.h" | 19 #include "ui/gfx/rect.h" |
| 20 | 20 |
| 21 using namespace WebKit; | 21 using namespace WebKit; |
| 22 | 22 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 , m_nextMailBox(1) | 94 , m_nextMailBox(1) |
| 95 { } | 95 { } |
| 96 | 96 |
| 97 unsigned m_nextSyncPoint; | 97 unsigned m_nextSyncPoint; |
| 98 unsigned m_nextMailBox; | 98 unsigned m_nextMailBox; |
| 99 typedef ScopedPtrHashMap<unsigned, Texture> TextureMap; | 99 typedef ScopedPtrHashMap<unsigned, Texture> TextureMap; |
| 100 TextureMap m_textures; | 100 TextureMap m_textures; |
| 101 base::hash_map<unsigned, unsigned> m_syncPointForMailbox; | 101 base::hash_map<unsigned, unsigned> m_syncPointForMailbox; |
| 102 }; | 102 }; |
| 103 | 103 |
| 104 class ResourceProviderContext : public FakeWebGraphicsContext3D { | 104 class ResourceProviderContext : public TestWebGraphicsContext3D { |
| 105 public: | 105 public: |
| 106 static scoped_ptr<ResourceProviderContext> create(ContextSharedData* sharedD
ata) { return make_scoped_ptr(new ResourceProviderContext(Attributes(), sharedDa
ta)); } | 106 static scoped_ptr<ResourceProviderContext> create(ContextSharedData* sharedD
ata) { return make_scoped_ptr(new ResourceProviderContext(Attributes(), sharedDa
ta)); } |
| 107 | 107 |
| 108 virtual unsigned insertSyncPoint() | 108 virtual unsigned insertSyncPoint() |
| 109 { | 109 { |
| 110 unsigned syncPoint = m_sharedData->insertSyncPoint(); | 110 unsigned syncPoint = m_sharedData->insertSyncPoint(); |
| 111 // Commit the produceTextureCHROMIUM calls at this point, so that | 111 // Commit the produceTextureCHROMIUM calls at this point, so that |
| 112 // they're associated with the sync point. | 112 // they're associated with the sync point. |
| 113 for (PendingProduceTextureList::iterator it = m_pendingProduceTextures.b
egin(); it != m_pendingProduceTextures.end(); ++it) | 113 for (PendingProduceTextureList::iterator it = m_pendingProduceTextures.b
egin(); it != m_pendingProduceTextures.end(); ++it) |
| 114 m_sharedData->produceTexture((*it)->mailbox, syncPoint, (*it)->textu
re.Pass()); | 114 m_sharedData->produceTexture((*it)->mailbox, syncPoint, (*it)->textu
re.Pass()); |
| 115 m_pendingProduceTextures.clear(); | 115 m_pendingProduceTextures.clear(); |
| 116 return syncPoint; | 116 return syncPoint; |
| 117 } | 117 } |
| 118 | 118 |
| 119 virtual void waitSyncPoint(unsigned syncPoint) | 119 virtual void waitSyncPoint(unsigned syncPoint) |
| 120 { | 120 { |
| 121 m_lastWaitedSyncPoint = std::max(syncPoint, m_lastWaitedSyncPoint); | 121 m_lastWaitedSyncPoint = std::max(syncPoint, m_lastWaitedSyncPoint); |
| 122 } | 122 } |
| 123 | 123 |
| 124 virtual void bindTexture(WGC3Denum target, WebGLId texture) | 124 virtual void bindTexture(WGC3Denum target, WebGLId texture) |
| 125 { | 125 { |
| 126 ASSERT_EQ(target, GL_TEXTURE_2D); | 126 ASSERT_EQ(target, GL_TEXTURE_2D); |
| 127 ASSERT_TRUE(!texture || m_textures.find(texture) != m_textures.end()); | 127 ASSERT_TRUE(!texture || m_textures.find(texture) != m_textures.end()); |
| 128 m_currentTexture = texture; | 128 m_currentTexture = texture; |
| 129 } | 129 } |
| 130 | 130 |
| 131 virtual WebGLId createTexture() | 131 virtual WebGLId createTexture() |
| 132 { | 132 { |
| 133 WebGLId id = FakeWebGraphicsContext3D::createTexture(); | 133 WebGLId id = TestWebGraphicsContext3D::createTexture(); |
| 134 m_textures.add(id, scoped_ptr<Texture>()); | 134 m_textures.add(id, scoped_ptr<Texture>()); |
| 135 return id; | 135 return id; |
| 136 } | 136 } |
| 137 | 137 |
| 138 virtual void deleteTexture(WebGLId id) | 138 virtual void deleteTexture(WebGLId id) |
| 139 { | 139 { |
| 140 TextureMap::iterator it = m_textures.find(id); | 140 TextureMap::iterator it = m_textures.find(id); |
| 141 ASSERT_FALSE(it == m_textures.end()); | 141 ASSERT_FALSE(it == m_textures.end()); |
| 142 m_textures.erase(it); | 142 m_textures.erase(it); |
| 143 if (m_currentTexture == id) | 143 if (m_currentTexture == id) |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 memcpy(pixels, texture->data.get(), textureSize(size, format)); | 221 memcpy(pixels, texture->data.get(), textureSize(size, format)); |
| 222 } | 222 } |
| 223 | 223 |
| 224 int textureCount() | 224 int textureCount() |
| 225 { | 225 { |
| 226 return m_textures.size(); | 226 return m_textures.size(); |
| 227 } | 227 } |
| 228 | 228 |
| 229 protected: | 229 protected: |
| 230 ResourceProviderContext(const Attributes& attrs, ContextSharedData* sharedDa
ta) | 230 ResourceProviderContext(const Attributes& attrs, ContextSharedData* sharedDa
ta) |
| 231 : FakeWebGraphicsContext3D(attrs) | 231 : TestWebGraphicsContext3D(attrs) |
| 232 , m_sharedData(sharedData) | 232 , m_sharedData(sharedData) |
| 233 , m_currentTexture(0) | 233 , m_currentTexture(0) |
| 234 , m_lastWaitedSyncPoint(0) | 234 , m_lastWaitedSyncPoint(0) |
| 235 { } | 235 { } |
| 236 | 236 |
| 237 private: | 237 private: |
| 238 void allocateTexture(const gfx::Size& size, WGC3Denum format) | 238 void allocateTexture(const gfx::Size& size, WGC3Denum format) |
| 239 { | 239 { |
| 240 ASSERT_TRUE(m_currentTexture); | 240 ASSERT_TRUE(m_currentTexture); |
| 241 m_textures.set(m_currentTexture, make_scoped_ptr(new Texture(size, forma
t))); | 241 m_textures.set(m_currentTexture, make_scoped_ptr(new Texture(size, forma
t))); |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 resourceIdsToTransfer.push_back(mappedId); | 557 resourceIdsToTransfer.push_back(mappedId); |
| 558 TransferableResourceList list; | 558 TransferableResourceList list; |
| 559 m_resourceProvider->prepareSendToChild(childId, resourceIdsToTransfer, &
list); | 559 m_resourceProvider->prepareSendToChild(childId, resourceIdsToTransfer, &
list); |
| 560 EXPECT_NE(0u, list.sync_point); | 560 EXPECT_NE(0u, list.sync_point); |
| 561 EXPECT_EQ(1u, list.resources.size()); | 561 EXPECT_EQ(1u, list.resources.size()); |
| 562 childResourceProvider->receiveFromParent(list); | 562 childResourceProvider->receiveFromParent(list); |
| 563 } | 563 } |
| 564 EXPECT_EQ(0u, childResourceProvider->numResources()); | 564 EXPECT_EQ(0u, childResourceProvider->numResources()); |
| 565 } | 565 } |
| 566 | 566 |
| 567 class TextureStateTrackingContext : public FakeWebGraphicsContext3D { | 567 class TextureStateTrackingContext : public TestWebGraphicsContext3D { |
| 568 public: | 568 public: |
| 569 MOCK_METHOD2(bindTexture, void(WGC3Denum target, WebGLId texture)); | 569 MOCK_METHOD2(bindTexture, void(WGC3Denum target, WebGLId texture)); |
| 570 MOCK_METHOD3(texParameteri, void(WGC3Denum target, WGC3Denum pname, WGC3Dint
param)); | 570 MOCK_METHOD3(texParameteri, void(WGC3Denum target, WGC3Denum pname, WGC3Dint
param)); |
| 571 | 571 |
| 572 // Force all textures to be "1" so we can test for them. | 572 // Force all textures to be "1" so we can test for them. |
| 573 virtual WebKit::WebGLId NextTextureId() { return 1; } | 573 virtual WebKit::WebGLId NextTextureId() { return 1; } |
| 574 }; | 574 }; |
| 575 | 575 |
| 576 TEST_P(ResourceProviderTest, ScopedSampler) | 576 TEST_P(ResourceProviderTest, ScopedSampler) |
| 577 { | 577 { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL
_LINEAR)); | 643 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL
_LINEAR)); |
| 644 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL
_LINEAR)); | 644 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL
_LINEAR)); |
| 645 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLA
MP_TO_EDGE)); | 645 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLA
MP_TO_EDGE)); |
| 646 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLA
MP_TO_EDGE)); | 646 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLA
MP_TO_EDGE)); |
| 647 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_POOL_CHROMIUM,
GL_TEXTURE_POOL_MANAGED_CHROMIUM)); | 647 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_POOL_CHROMIUM,
GL_TEXTURE_POOL_MANAGED_CHROMIUM)); |
| 648 ResourceProvider::ResourceId id = resourceProvider->createManagedResource(si
ze, format, ResourceProvider::TextureUsageAny); | 648 ResourceProvider::ResourceId id = resourceProvider->createManagedResource(si
ze, format, ResourceProvider::TextureUsageAny); |
| 649 | 649 |
| 650 Mock::VerifyAndClearExpectations(context); | 650 Mock::VerifyAndClearExpectations(context); |
| 651 } | 651 } |
| 652 | 652 |
| 653 class AllocationTrackingContext3D : public FakeWebGraphicsContext3D { | 653 class AllocationTrackingContext3D : public TestWebGraphicsContext3D { |
| 654 public: | 654 public: |
| 655 MOCK_METHOD0(createTexture, WebGLId()); | 655 MOCK_METHOD0(createTexture, WebGLId()); |
| 656 MOCK_METHOD1(deleteTexture, void(WebGLId texture_id)); | 656 MOCK_METHOD1(deleteTexture, void(WebGLId texture_id)); |
| 657 MOCK_METHOD2(bindTexture, void(WGC3Denum target, WebGLId texture)); | 657 MOCK_METHOD2(bindTexture, void(WGC3Denum target, WebGLId texture)); |
| 658 MOCK_METHOD9(texImage2D, void(WGC3Denum target, WGC3Dint level, WGC3Denum in
ternalformat, | 658 MOCK_METHOD9(texImage2D, void(WGC3Denum target, WGC3Dint level, WGC3Denum in
ternalformat, |
| 659 WGC3Dsizei width, WGC3Dsizei height, WGC3Dint
border, WGC3Denum format, | 659 WGC3Dsizei width, WGC3Dsizei height, WGC3Dint
border, WGC3Denum format, |
| 660 WGC3Denum type, const void* pixels)); | 660 WGC3Denum type, const void* pixels)); |
| 661 MOCK_METHOD9(texSubImage2D, void(WGC3Denum target, WGC3Dint level, WGC3Dint
xoffset, WGC3Dint yoffset, | 661 MOCK_METHOD9(texSubImage2D, void(WGC3Denum target, WGC3Dint level, WGC3Dint
xoffset, WGC3Dint yoffset, |
| 662 WGC3Dsizei width, WGC3Dsizei height, WGC3De
num format, | 662 WGC3Dsizei width, WGC3Dsizei height, WGC3De
num format, |
| 663 WGC3Denum type, const void* pixels)); | 663 WGC3Denum type, const void* pixels)); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 Mock::VerifyAndClearExpectations(context); | 736 Mock::VerifyAndClearExpectations(context); |
| 737 } | 737 } |
| 738 | 738 |
| 739 INSTANTIATE_TEST_CASE_P(ResourceProviderTests, | 739 INSTANTIATE_TEST_CASE_P(ResourceProviderTests, |
| 740 ResourceProviderTest, | 740 ResourceProviderTest, |
| 741 ::testing::Values(ResourceProvider::GLTexture, | 741 ::testing::Values(ResourceProvider::GLTexture, |
| 742 ResourceProvider::Bitmap)); | 742 ResourceProvider::Bitmap)); |
| 743 | 743 |
| 744 } // namespace | 744 } // namespace |
| 745 } // namespace cc | 745 } // namespace cc |
| OLD | NEW |