| 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_web_compositor_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; |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 WebGLId m_currentTexture; | 265 WebGLId m_currentTexture; |
| 266 TextureMap m_textures; | 266 TextureMap m_textures; |
| 267 unsigned m_lastWaitedSyncPoint; | 267 unsigned m_lastWaitedSyncPoint; |
| 268 PendingProduceTextureList m_pendingProduceTextures; | 268 PendingProduceTextureList m_pendingProduceTextures; |
| 269 }; | 269 }; |
| 270 | 270 |
| 271 class ResourceProviderTest : public testing::TestWithParam<ResourceProvider::Res
ourceType> { | 271 class ResourceProviderTest : public testing::TestWithParam<ResourceProvider::Res
ourceType> { |
| 272 public: | 272 public: |
| 273 ResourceProviderTest() | 273 ResourceProviderTest() |
| 274 : m_sharedData(ContextSharedData::create()) | 274 : m_sharedData(ContextSharedData::create()) |
| 275 , m_outputSurface(FakeWebCompositorOutputSurface::create(ResourceProvide
rContext::create(m_sharedData.get()).PassAs<WebKit::WebGraphicsContext3D>().Pass
As<WebKit::WebGraphicsContext3D>())) | 275 , m_outputSurface(FakeOutputSurface::Create3d(ResourceProviderContext::c
reate(m_sharedData.get()).PassAs<WebKit::WebGraphicsContext3D>().PassAs<WebKit::
WebGraphicsContext3D>())) |
| 276 , m_resourceProvider(ResourceProvider::create(m_outputSurface.get())) | 276 , m_resourceProvider(ResourceProvider::create(m_outputSurface.get())) |
| 277 { | 277 { |
| 278 m_resourceProvider->setDefaultResourceType(GetParam()); | 278 m_resourceProvider->setDefaultResourceType(GetParam()); |
| 279 } | 279 } |
| 280 | 280 |
| 281 ResourceProviderContext* context() { return static_cast<ResourceProviderCont
ext*>(m_outputSurface->context3D()); } | 281 ResourceProviderContext* context() { return static_cast<ResourceProviderCont
ext*>(m_outputSurface->Context3D()); } |
| 282 | 282 |
| 283 void getResourcePixels(ResourceProvider::ResourceId id, const gfx::Size& siz
e, WGC3Denum format, uint8_t* pixels) | 283 void getResourcePixels(ResourceProvider::ResourceId id, const gfx::Size& siz
e, WGC3Denum format, uint8_t* pixels) |
| 284 { | 284 { |
| 285 if (GetParam() == ResourceProvider::GLTexture) { | 285 if (GetParam() == ResourceProvider::GLTexture) { |
| 286 ResourceProvider::ScopedReadLockGL lockGL(m_resourceProvider.get(),
id); | 286 ResourceProvider::ScopedReadLockGL lockGL(m_resourceProvider.get(),
id); |
| 287 ASSERT_NE(0U, lockGL.textureId()); | 287 ASSERT_NE(0U, lockGL.textureId()); |
| 288 context()->bindTexture(GL_TEXTURE_2D, lockGL.textureId()); | 288 context()->bindTexture(GL_TEXTURE_2D, lockGL.textureId()); |
| 289 context()->getPixels(size, format, pixels); | 289 context()->getPixels(size, format, pixels); |
| 290 } else if (GetParam() == ResourceProvider::Bitmap) { | 290 } else if (GetParam() == ResourceProvider::Bitmap) { |
| 291 ResourceProvider::ScopedReadLockSoftware lockSoftware(m_resourceProv
ider.get(), id); | 291 ResourceProvider::ScopedReadLockSoftware lockSoftware(m_resourceProv
ider.get(), id); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 | 410 |
| 411 m_resourceProvider->deleteResource(id); | 411 m_resourceProvider->deleteResource(id); |
| 412 } | 412 } |
| 413 | 413 |
| 414 TEST_P(ResourceProviderTest, TransferResources) | 414 TEST_P(ResourceProviderTest, TransferResources) |
| 415 { | 415 { |
| 416 // Resource transfer is only supported with GL textures for now. | 416 // Resource transfer is only supported with GL textures for now. |
| 417 if (GetParam() != ResourceProvider::GLTexture) | 417 if (GetParam() != ResourceProvider::GLTexture) |
| 418 return; | 418 return; |
| 419 | 419 |
| 420 scoped_ptr<OutputSurface> childOutputSurface(FakeWebCompositorOutputSurface:
:create(ResourceProviderContext::create(m_sharedData.get()).PassAs<WebKit::WebGr
aphicsContext3D>())); | 420 scoped_ptr<OutputSurface> childOutputSurface(FakeOutputSurface::Create3d(Res
ourceProviderContext::create(m_sharedData.get()).PassAs<WebKit::WebGraphicsConte
xt3D>())); |
| 421 scoped_ptr<ResourceProvider> childResourceProvider(ResourceProvider::create(
childOutputSurface.get())); | 421 scoped_ptr<ResourceProvider> childResourceProvider(ResourceProvider::create(
childOutputSurface.get())); |
| 422 | 422 |
| 423 gfx::Size size(1, 1); | 423 gfx::Size size(1, 1); |
| 424 WGC3Denum format = GL_RGBA; | 424 WGC3Denum format = GL_RGBA; |
| 425 int pool = 1; | 425 int pool = 1; |
| 426 size_t pixelSize = textureSize(size, format); | 426 size_t pixelSize = textureSize(size, format); |
| 427 ASSERT_EQ(4U, pixelSize); | 427 ASSERT_EQ(4U, pixelSize); |
| 428 | 428 |
| 429 ResourceProvider::ResourceId id1 = childResourceProvider->createResource(poo
l, size, format, ResourceProvider::TextureUsageAny); | 429 ResourceProvider::ResourceId id1 = childResourceProvider->createResource(poo
l, size, format, ResourceProvider::TextureUsageAny); |
| 430 uint8_t data1[4] = {1, 2, 3, 4}; | 430 uint8_t data1[4] = {1, 2, 3, 4}; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 resourceIdsToTransfer.push_back(mappedId2); | 486 resourceIdsToTransfer.push_back(mappedId2); |
| 487 TransferableResourceList list; | 487 TransferableResourceList list; |
| 488 m_resourceProvider->prepareSendToChild(childId, resourceIdsToTransfer, &
list); | 488 m_resourceProvider->prepareSendToChild(childId, resourceIdsToTransfer, &
list); |
| 489 EXPECT_NE(0u, list.sync_point); | 489 EXPECT_NE(0u, list.sync_point); |
| 490 EXPECT_EQ(2u, list.resources.size()); | 490 EXPECT_EQ(2u, list.resources.size()); |
| 491 childResourceProvider->receiveFromParent(list); | 491 childResourceProvider->receiveFromParent(list); |
| 492 } | 492 } |
| 493 EXPECT_FALSE(childResourceProvider->inUseByConsumer(id1)); | 493 EXPECT_FALSE(childResourceProvider->inUseByConsumer(id1)); |
| 494 EXPECT_FALSE(childResourceProvider->inUseByConsumer(id2)); | 494 EXPECT_FALSE(childResourceProvider->inUseByConsumer(id2)); |
| 495 | 495 |
| 496 ResourceProviderContext* childContext3D = static_cast<ResourceProviderContex
t*>(childOutputSurface->context3D()); | 496 ResourceProviderContext* childContext3D = static_cast<ResourceProviderContex
t*>(childOutputSurface->Context3D()); |
| 497 { | 497 { |
| 498 ResourceProvider::ScopedReadLockGL lock(childResourceProvider.get(), id1
); | 498 ResourceProvider::ScopedReadLockGL lock(childResourceProvider.get(), id1
); |
| 499 ASSERT_NE(0U, lock.textureId()); | 499 ASSERT_NE(0U, lock.textureId()); |
| 500 childContext3D->bindTexture(GL_TEXTURE_2D, lock.textureId()); | 500 childContext3D->bindTexture(GL_TEXTURE_2D, lock.textureId()); |
| 501 childContext3D->getPixels(size, format, result); | 501 childContext3D->getPixels(size, format, result); |
| 502 EXPECT_EQ(0, memcmp(data1, result, pixelSize)); | 502 EXPECT_EQ(0, memcmp(data1, result, pixelSize)); |
| 503 } | 503 } |
| 504 { | 504 { |
| 505 ResourceProvider::ScopedReadLockGL lock(childResourceProvider.get(), id2
); | 505 ResourceProvider::ScopedReadLockGL lock(childResourceProvider.get(), id2
); |
| 506 ASSERT_NE(0U, lock.textureId()); | 506 ASSERT_NE(0U, lock.textureId()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 527 m_resourceProvider->destroyChild(childId); | 527 m_resourceProvider->destroyChild(childId); |
| 528 EXPECT_EQ(0u, m_resourceProvider->numResources()); | 528 EXPECT_EQ(0u, m_resourceProvider->numResources()); |
| 529 } | 529 } |
| 530 | 530 |
| 531 TEST_P(ResourceProviderTest, DeleteTransferredResources) | 531 TEST_P(ResourceProviderTest, DeleteTransferredResources) |
| 532 { | 532 { |
| 533 // Resource transfer is only supported with GL textures for now. | 533 // Resource transfer is only supported with GL textures for now. |
| 534 if (GetParam() != ResourceProvider::GLTexture) | 534 if (GetParam() != ResourceProvider::GLTexture) |
| 535 return; | 535 return; |
| 536 | 536 |
| 537 scoped_ptr<OutputSurface> childOutputSurface(FakeWebCompositorOutputSurface:
:create(ResourceProviderContext::create(m_sharedData.get()).PassAs<WebKit::WebGr
aphicsContext3D>())); | 537 scoped_ptr<OutputSurface> childOutputSurface(FakeOutputSurface::Create3d(Res
ourceProviderContext::create(m_sharedData.get()).PassAs<WebKit::WebGraphicsConte
xt3D>())); |
| 538 scoped_ptr<ResourceProvider> childResourceProvider(ResourceProvider::create(
childOutputSurface.get())); | 538 scoped_ptr<ResourceProvider> childResourceProvider(ResourceProvider::create(
childOutputSurface.get())); |
| 539 | 539 |
| 540 gfx::Size size(1, 1); | 540 gfx::Size size(1, 1); |
| 541 WGC3Denum format = GL_RGBA; | 541 WGC3Denum format = GL_RGBA; |
| 542 int pool = 1; | 542 int pool = 1; |
| 543 size_t pixelSize = textureSize(size, format); | 543 size_t pixelSize = textureSize(size, format); |
| 544 ASSERT_EQ(4U, pixelSize); | 544 ASSERT_EQ(4U, pixelSize); |
| 545 | 545 |
| 546 ResourceProvider::ResourceId id = childResourceProvider->createResource(pool
, size, format, ResourceProvider::TextureUsageAny); | 546 ResourceProvider::ResourceId id = childResourceProvider->createResource(pool
, size, format, ResourceProvider::TextureUsageAny); |
| 547 uint8_t data[4] = {1, 2, 3, 4}; | 547 uint8_t data[4] = {1, 2, 3, 4}; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 MOCK_METHOD2(bindTexture, void(WGC3Denum target, WebGLId texture)); | 588 MOCK_METHOD2(bindTexture, void(WGC3Denum target, WebGLId texture)); |
| 589 MOCK_METHOD3(texParameteri, void(WGC3Denum target, WGC3Denum pname, WGC3Dint
param)); | 589 MOCK_METHOD3(texParameteri, void(WGC3Denum target, WGC3Denum pname, WGC3Dint
param)); |
| 590 }; | 590 }; |
| 591 | 591 |
| 592 TEST_P(ResourceProviderTest, ScopedSampler) | 592 TEST_P(ResourceProviderTest, ScopedSampler) |
| 593 { | 593 { |
| 594 // Sampling is only supported for GL textures. | 594 // Sampling is only supported for GL textures. |
| 595 if (GetParam() != ResourceProvider::GLTexture) | 595 if (GetParam() != ResourceProvider::GLTexture) |
| 596 return; | 596 return; |
| 597 | 597 |
| 598 scoped_ptr<OutputSurface> outputSurface(FakeWebCompositorOutputSurface::crea
te(scoped_ptr<WebKit::WebGraphicsContext3D>(new TextureStateTrackingContext))); | 598 scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_p
tr<WebKit::WebGraphicsContext3D>(new TextureStateTrackingContext))); |
| 599 TextureStateTrackingContext* context = static_cast<TextureStateTrackingConte
xt*>(outputSurface->context3D()); | 599 TextureStateTrackingContext* context = static_cast<TextureStateTrackingConte
xt*>(outputSurface->Context3D()); |
| 600 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu
tSurface.get())); | 600 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu
tSurface.get())); |
| 601 | 601 |
| 602 gfx::Size size(1, 1); | 602 gfx::Size size(1, 1); |
| 603 WGC3Denum format = GL_RGBA; | 603 WGC3Denum format = GL_RGBA; |
| 604 int pool = 1; | 604 int pool = 1; |
| 605 int textureId = 1; | 605 int textureId = 1; |
| 606 | 606 |
| 607 // Check that the texture gets created with the right sampler settings. | 607 // Check that the texture gets created with the right sampler settings. |
| 608 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, textureId)); | 608 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, textureId)); |
| 609 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL
_LINEAR)); | 609 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL
_LINEAR)); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 638 Mock::VerifyAndClearExpectations(context); | 638 Mock::VerifyAndClearExpectations(context); |
| 639 } | 639 } |
| 640 | 640 |
| 641 INSTANTIATE_TEST_CASE_P(ResourceProviderTests, | 641 INSTANTIATE_TEST_CASE_P(ResourceProviderTests, |
| 642 ResourceProviderTest, | 642 ResourceProviderTest, |
| 643 ::testing::Values(ResourceProvider::GLTexture, | 643 ::testing::Values(ResourceProvider::GLTexture, |
| 644 ResourceProvider::Bitmap)); | 644 ResourceProvider::Bitmap)); |
| 645 | 645 |
| 646 } // namespace | 646 } // namespace |
| 647 } // namespace cc | 647 } // namespace cc |
| OLD | NEW |