| 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" |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 class ResourceProviderTest : public testing::TestWithParam<ResourceProvider::Res
ourceType> { | 276 class ResourceProviderTest : public testing::TestWithParam<ResourceProvider::Res
ourceType> { |
| 277 public: | 277 public: |
| 278 ResourceProviderTest() | 278 ResourceProviderTest() |
| 279 : m_sharedData(ContextSharedData::create()) | 279 : m_sharedData(ContextSharedData::create()) |
| 280 , m_outputSurface(FakeOutputSurface::Create3d(ResourceProviderContext::c
reate(m_sharedData.get()).PassAs<WebKit::WebGraphicsContext3D>().PassAs<WebKit::
WebGraphicsContext3D>())) | 280 , m_outputSurface(FakeOutputSurface::Create3d(ResourceProviderContext::c
reate(m_sharedData.get()).PassAs<WebKit::WebGraphicsContext3D>().PassAs<WebKit::
WebGraphicsContext3D>())) |
| 281 , m_resourceProvider(ResourceProvider::create(m_outputSurface.get())) | 281 , m_resourceProvider(ResourceProvider::create(m_outputSurface.get())) |
| 282 { | 282 { |
| 283 m_resourceProvider->setDefaultResourceType(GetParam()); | 283 m_resourceProvider->setDefaultResourceType(GetParam()); |
| 284 } | 284 } |
| 285 | 285 |
| 286 ResourceProviderContext* context() { return static_cast<ResourceProviderCont
ext*>(m_outputSurface->Context3D()); } | 286 ResourceProviderContext* context() { return static_cast<ResourceProviderCont
ext*>(m_outputSurface->context3d()); } |
| 287 | 287 |
| 288 void getResourcePixels(ResourceProvider::ResourceId id, const gfx::Size& siz
e, WGC3Denum format, uint8_t* pixels) | 288 void getResourcePixels(ResourceProvider::ResourceId id, const gfx::Size& siz
e, WGC3Denum format, uint8_t* pixels) |
| 289 { | 289 { |
| 290 if (GetParam() == ResourceProvider::GLTexture) { | 290 if (GetParam() == ResourceProvider::GLTexture) { |
| 291 ResourceProvider::ScopedReadLockGL lockGL(m_resourceProvider.get(),
id); | 291 ResourceProvider::ScopedReadLockGL lockGL(m_resourceProvider.get(),
id); |
| 292 ASSERT_NE(0U, lockGL.textureId()); | 292 ASSERT_NE(0U, lockGL.textureId()); |
| 293 context()->bindTexture(GL_TEXTURE_2D, lockGL.textureId()); | 293 context()->bindTexture(GL_TEXTURE_2D, lockGL.textureId()); |
| 294 context()->getPixels(size, format, pixels); | 294 context()->getPixels(size, format, pixels); |
| 295 } else if (GetParam() == ResourceProvider::Bitmap) { | 295 } else if (GetParam() == ResourceProvider::Bitmap) { |
| 296 ResourceProvider::ScopedReadLockSoftware lockSoftware(m_resourceProv
ider.get(), id); | 296 ResourceProvider::ScopedReadLockSoftware lockSoftware(m_resourceProv
ider.get(), id); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 resourceIdsToTransfer.push_back(mappedId2); | 469 resourceIdsToTransfer.push_back(mappedId2); |
| 470 TransferableResourceList list; | 470 TransferableResourceList list; |
| 471 m_resourceProvider->prepareSendToChild(childId, resourceIdsToTransfer, &
list); | 471 m_resourceProvider->prepareSendToChild(childId, resourceIdsToTransfer, &
list); |
| 472 EXPECT_NE(0u, list.sync_point); | 472 EXPECT_NE(0u, list.sync_point); |
| 473 EXPECT_EQ(2u, list.resources.size()); | 473 EXPECT_EQ(2u, list.resources.size()); |
| 474 childResourceProvider->receiveFromParent(list); | 474 childResourceProvider->receiveFromParent(list); |
| 475 } | 475 } |
| 476 EXPECT_FALSE(childResourceProvider->inUseByConsumer(id1)); | 476 EXPECT_FALSE(childResourceProvider->inUseByConsumer(id1)); |
| 477 EXPECT_FALSE(childResourceProvider->inUseByConsumer(id2)); | 477 EXPECT_FALSE(childResourceProvider->inUseByConsumer(id2)); |
| 478 | 478 |
| 479 ResourceProviderContext* childContext3D = static_cast<ResourceProviderContex
t*>(childOutputSurface->Context3D()); | 479 ResourceProviderContext* childContext3D = static_cast<ResourceProviderContex
t*>(childOutputSurface->context3d()); |
| 480 { | 480 { |
| 481 ResourceProvider::ScopedReadLockGL lock(childResourceProvider.get(), id1
); | 481 ResourceProvider::ScopedReadLockGL lock(childResourceProvider.get(), id1
); |
| 482 ASSERT_NE(0U, lock.textureId()); | 482 ASSERT_NE(0U, lock.textureId()); |
| 483 childContext3D->bindTexture(GL_TEXTURE_2D, lock.textureId()); | 483 childContext3D->bindTexture(GL_TEXTURE_2D, lock.textureId()); |
| 484 childContext3D->getPixels(size, format, result); | 484 childContext3D->getPixels(size, format, result); |
| 485 EXPECT_EQ(0, memcmp(data1, result, pixelSize)); | 485 EXPECT_EQ(0, memcmp(data1, result, pixelSize)); |
| 486 } | 486 } |
| 487 { | 487 { |
| 488 ResourceProvider::ScopedReadLockGL lock(childResourceProvider.get(), id2
); | 488 ResourceProvider::ScopedReadLockGL lock(childResourceProvider.get(), id2
); |
| 489 ASSERT_NE(0U, lock.textureId()); | 489 ASSERT_NE(0U, lock.textureId()); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 { |
| 578 // Sampling is only supported for GL textures. | 578 // Sampling is only supported for GL textures. |
| 579 if (GetParam() != ResourceProvider::GLTexture) | 579 if (GetParam() != ResourceProvider::GLTexture) |
| 580 return; | 580 return; |
| 581 | 581 |
| 582 scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_p
tr<WebKit::WebGraphicsContext3D>(new TextureStateTrackingContext))); | 582 scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_p
tr<WebKit::WebGraphicsContext3D>(new TextureStateTrackingContext))); |
| 583 TextureStateTrackingContext* context = static_cast<TextureStateTrackingConte
xt*>(outputSurface->Context3D()); | 583 TextureStateTrackingContext* context = static_cast<TextureStateTrackingConte
xt*>(outputSurface->context3d()); |
| 584 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu
tSurface.get())); | 584 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu
tSurface.get())); |
| 585 | 585 |
| 586 gfx::Size size(1, 1); | 586 gfx::Size size(1, 1); |
| 587 WGC3Denum format = GL_RGBA; | 587 WGC3Denum format = GL_RGBA; |
| 588 int textureId = 1; | 588 int textureId = 1; |
| 589 | 589 |
| 590 // Check that the texture gets created with the right sampler settings. | 590 // Check that the texture gets created with the right sampler settings. |
| 591 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, textureId)) | 591 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, textureId)) |
| 592 .Times(2); // Once to create and once to allocate. | 592 .Times(2); // Once to create and once to allocate. |
| 593 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL
_LINEAR)); | 593 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL
_LINEAR)); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 624 Mock::VerifyAndClearExpectations(context); | 624 Mock::VerifyAndClearExpectations(context); |
| 625 } | 625 } |
| 626 | 626 |
| 627 TEST_P(ResourceProviderTest, ManagedResource) | 627 TEST_P(ResourceProviderTest, ManagedResource) |
| 628 { | 628 { |
| 629 // Sampling is only supported for GL textures. | 629 // Sampling is only supported for GL textures. |
| 630 if (GetParam() != ResourceProvider::GLTexture) | 630 if (GetParam() != ResourceProvider::GLTexture) |
| 631 return; | 631 return; |
| 632 | 632 |
| 633 scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_p
tr<WebKit::WebGraphicsContext3D>(new TextureStateTrackingContext))); | 633 scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_p
tr<WebKit::WebGraphicsContext3D>(new TextureStateTrackingContext))); |
| 634 TextureStateTrackingContext* context = static_cast<TextureStateTrackingConte
xt*>(outputSurface->Context3D()); | 634 TextureStateTrackingContext* context = static_cast<TextureStateTrackingConte
xt*>(outputSurface->context3d()); |
| 635 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu
tSurface.get())); | 635 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu
tSurface.get())); |
| 636 | 636 |
| 637 gfx::Size size(1, 1); | 637 gfx::Size size(1, 1); |
| 638 WGC3Denum format = GL_RGBA; | 638 WGC3Denum format = GL_RGBA; |
| 639 int textureId = 1; | 639 int textureId = 1; |
| 640 | 640 |
| 641 // Check that the texture gets created with the right sampler settings. | 641 // Check that the texture gets created with the right sampler settings. |
| 642 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, textureId)); | 642 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, textureId)); |
| 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)); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(mock_con
text.Pass())); | 679 scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(mock_con
text.Pass())); |
| 680 | 680 |
| 681 gfx::Size size(2, 2); | 681 gfx::Size size(2, 2); |
| 682 gfx::Vector2d offset(0, 0); | 682 gfx::Vector2d offset(0, 0); |
| 683 gfx::Rect rect(0, 0, 2, 2); | 683 gfx::Rect rect(0, 0, 2, 2); |
| 684 WGC3Denum format = GL_RGBA; | 684 WGC3Denum format = GL_RGBA; |
| 685 ResourceProvider::ResourceId id = 0; | 685 ResourceProvider::ResourceId id = 0; |
| 686 uint8_t pixels[16] = {0}; | 686 uint8_t pixels[16] = {0}; |
| 687 int textureId = 123; | 687 int textureId = 123; |
| 688 | 688 |
| 689 AllocationTrackingContext3D* context = static_cast<AllocationTrackingContext
3D*>(outputSurface->Context3D()); | 689 AllocationTrackingContext3D* context = static_cast<AllocationTrackingContext
3D*>(outputSurface->context3d()); |
| 690 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu
tSurface.get())); | 690 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu
tSurface.get())); |
| 691 | 691 |
| 692 // Lazy allocation. Don't allocate when creating the resource. | 692 // Lazy allocation. Don't allocate when creating the resource. |
| 693 EXPECT_CALL(*context, createTexture()).WillOnce(Return(textureId)); | 693 EXPECT_CALL(*context, createTexture()).WillOnce(Return(textureId)); |
| 694 EXPECT_CALL(*context, deleteTexture(textureId)).Times(1); | 694 EXPECT_CALL(*context, deleteTexture(textureId)).Times(1); |
| 695 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, textureId)).Times(1); | 695 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, textureId)).Times(1); |
| 696 EXPECT_CALL(*context, texImage2D(_,_,_,_,_,_,_,_,_)).Times(0); | 696 EXPECT_CALL(*context, texImage2D(_,_,_,_,_,_,_,_,_)).Times(0); |
| 697 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_,_,_,_,_,_,_,_,_)).Times(0); | 697 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_,_,_,_,_,_,_,_,_)).Times(0); |
| 698 id = resourceProvider->createResource(size, format, ResourceProvider::Textur
eUsageAny); | 698 id = resourceProvider->createResource(size, format, ResourceProvider::Textur
eUsageAny); |
| 699 resourceProvider->deleteResource(id); | 699 resourceProvider->deleteResource(id); |
| (...skipping 36 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 |