| 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 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 protected: | 303 protected: |
| 304 scoped_ptr<ContextSharedData> m_sharedData; | 304 scoped_ptr<ContextSharedData> m_sharedData; |
| 305 scoped_ptr<OutputSurface> m_outputSurface; | 305 scoped_ptr<OutputSurface> m_outputSurface; |
| 306 scoped_ptr<ResourceProvider> m_resourceProvider; | 306 scoped_ptr<ResourceProvider> m_resourceProvider; |
| 307 }; | 307 }; |
| 308 | 308 |
| 309 TEST_P(ResourceProviderTest, Basic) | 309 TEST_P(ResourceProviderTest, Basic) |
| 310 { | 310 { |
| 311 gfx::Size size(1, 1); | 311 gfx::Size size(1, 1); |
| 312 WGC3Denum format = GL_RGBA; | 312 WGC3Denum format = GL_RGBA; |
| 313 int pool = 1; | |
| 314 size_t pixelSize = textureSize(size, format); | 313 size_t pixelSize = textureSize(size, format); |
| 315 ASSERT_EQ(4U, pixelSize); | 314 ASSERT_EQ(4U, pixelSize); |
| 316 | 315 |
| 317 ResourceProvider::ResourceId id = m_resourceProvider->createResource(pool, s
ize, format, ResourceProvider::TextureUsageAny); | 316 ResourceProvider::ResourceId id = m_resourceProvider->createResource(size, f
ormat, ResourceProvider::TextureUsageAny); |
| 318 expectNumResources(1); | 317 expectNumResources(1); |
| 319 | 318 |
| 320 uint8_t data[4] = {1, 2, 3, 4}; | 319 uint8_t data[4] = {1, 2, 3, 4}; |
| 321 gfx::Rect rect(gfx::Point(), size); | 320 gfx::Rect rect(gfx::Point(), size); |
| 322 m_resourceProvider->setPixels(id, data, rect, rect, gfx::Vector2d()); | 321 m_resourceProvider->setPixels(id, data, rect, rect, gfx::Vector2d()); |
| 323 | 322 |
| 324 uint8_t result[4] = {0}; | 323 uint8_t result[4] = {0}; |
| 325 getResourcePixels(id, size, format, result); | 324 getResourcePixels(id, size, format, result); |
| 326 EXPECT_EQ(0, memcmp(data, result, pixelSize)); | 325 EXPECT_EQ(0, memcmp(data, result, pixelSize)); |
| 327 | 326 |
| 328 m_resourceProvider->deleteResource(id); | 327 m_resourceProvider->deleteResource(id); |
| 329 expectNumResources(0); | 328 expectNumResources(0); |
| 330 } | 329 } |
| 331 | 330 |
| 332 TEST_P(ResourceProviderTest, DeleteOwnedResources) | |
| 333 { | |
| 334 gfx::Size size(1, 1); | |
| 335 WGC3Denum format = GL_RGBA; | |
| 336 int pool = 1; | |
| 337 | |
| 338 const int count = 3; | |
| 339 for (int i = 0; i < count; ++i) | |
| 340 m_resourceProvider->createResource(pool, size, format, ResourceProvider:
:TextureUsageAny); | |
| 341 expectNumResources(3); | |
| 342 | |
| 343 m_resourceProvider->deleteOwnedResources(pool+1); | |
| 344 expectNumResources(3); | |
| 345 | |
| 346 m_resourceProvider->deleteOwnedResources(pool); | |
| 347 expectNumResources(0); | |
| 348 } | |
| 349 | |
| 350 TEST_P(ResourceProviderTest, Upload) | 331 TEST_P(ResourceProviderTest, Upload) |
| 351 { | 332 { |
| 352 gfx::Size size(2, 2); | 333 gfx::Size size(2, 2); |
| 353 WGC3Denum format = GL_RGBA; | 334 WGC3Denum format = GL_RGBA; |
| 354 int pool = 1; | |
| 355 size_t pixelSize = textureSize(size, format); | 335 size_t pixelSize = textureSize(size, format); |
| 356 ASSERT_EQ(16U, pixelSize); | 336 ASSERT_EQ(16U, pixelSize); |
| 357 | 337 |
| 358 ResourceProvider::ResourceId id = m_resourceProvider->createResource(pool, s
ize, format, ResourceProvider::TextureUsageAny); | 338 ResourceProvider::ResourceId id = m_resourceProvider->createResource(size, f
ormat, ResourceProvider::TextureUsageAny); |
| 359 | 339 |
| 360 uint8_t image[16] = {0}; | 340 uint8_t image[16] = {0}; |
| 361 gfx::Rect imageRect(gfx::Point(), size); | 341 gfx::Rect imageRect(gfx::Point(), size); |
| 362 m_resourceProvider->setPixels(id, image, imageRect, imageRect, gfx::Vector2d
()); | 342 m_resourceProvider->setPixels(id, image, imageRect, imageRect, gfx::Vector2d
()); |
| 363 | 343 |
| 364 for (uint8_t i = 0 ; i < pixelSize; ++i) | 344 for (uint8_t i = 0 ; i < pixelSize; ++i) |
| 365 image[i] = i; | 345 image[i] = i; |
| 366 | 346 |
| 367 uint8_t result[16] = {0}; | 347 uint8_t result[16] = {0}; |
| 368 { | 348 { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 { | 395 { |
| 416 // Resource transfer is only supported with GL textures for now. | 396 // Resource transfer is only supported with GL textures for now. |
| 417 if (GetParam() != ResourceProvider::GLTexture) | 397 if (GetParam() != ResourceProvider::GLTexture) |
| 418 return; | 398 return; |
| 419 | 399 |
| 420 scoped_ptr<OutputSurface> childOutputSurface(FakeOutputSurface::Create3d(Res
ourceProviderContext::create(m_sharedData.get()).PassAs<WebKit::WebGraphicsConte
xt3D>())); | 400 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())); | 401 scoped_ptr<ResourceProvider> childResourceProvider(ResourceProvider::create(
childOutputSurface.get())); |
| 422 | 402 |
| 423 gfx::Size size(1, 1); | 403 gfx::Size size(1, 1); |
| 424 WGC3Denum format = GL_RGBA; | 404 WGC3Denum format = GL_RGBA; |
| 425 int pool = 1; | |
| 426 size_t pixelSize = textureSize(size, format); | 405 size_t pixelSize = textureSize(size, format); |
| 427 ASSERT_EQ(4U, pixelSize); | 406 ASSERT_EQ(4U, pixelSize); |
| 428 | 407 |
| 429 ResourceProvider::ResourceId id1 = childResourceProvider->createResource(poo
l, size, format, ResourceProvider::TextureUsageAny); | 408 ResourceProvider::ResourceId id1 = childResourceProvider->createResource(siz
e, format, ResourceProvider::TextureUsageAny); |
| 430 uint8_t data1[4] = {1, 2, 3, 4}; | 409 uint8_t data1[4] = {1, 2, 3, 4}; |
| 431 gfx::Rect rect(gfx::Point(), size); | 410 gfx::Rect rect(gfx::Point(), size); |
| 432 childResourceProvider->setPixels(id1, data1, rect, rect, gfx::Vector2d()); | 411 childResourceProvider->setPixels(id1, data1, rect, rect, gfx::Vector2d()); |
| 433 | 412 |
| 434 ResourceProvider::ResourceId id2 = childResourceProvider->createResource(poo
l, size, format, ResourceProvider::TextureUsageAny); | 413 ResourceProvider::ResourceId id2 = childResourceProvider->createResource(siz
e, format, ResourceProvider::TextureUsageAny); |
| 435 uint8_t data2[4] = {5, 5, 5, 5}; | 414 uint8_t data2[4] = {5, 5, 5, 5}; |
| 436 childResourceProvider->setPixels(id2, data2, rect, rect, gfx::Vector2d()); | 415 childResourceProvider->setPixels(id2, data2, rect, rect, gfx::Vector2d()); |
| 437 | 416 |
| 438 int childPool = 2; | 417 int childId = m_resourceProvider->createChild(); |
| 439 int childId = m_resourceProvider->createChild(childPool); | |
| 440 | 418 |
| 441 { | 419 { |
| 442 // Transfer some resources to the parent. | 420 // Transfer some resources to the parent. |
| 443 ResourceProvider::ResourceIdArray resourceIdsToTransfer; | 421 ResourceProvider::ResourceIdArray resourceIdsToTransfer; |
| 444 resourceIdsToTransfer.push_back(id1); | 422 resourceIdsToTransfer.push_back(id1); |
| 445 resourceIdsToTransfer.push_back(id2); | 423 resourceIdsToTransfer.push_back(id2); |
| 446 TransferableResourceList list; | 424 TransferableResourceList list; |
| 447 childResourceProvider->prepareSendToParent(resourceIdsToTransfer, &list)
; | 425 childResourceProvider->prepareSendToParent(resourceIdsToTransfer, &list)
; |
| 448 EXPECT_NE(0u, list.sync_point); | 426 EXPECT_NE(0u, list.sync_point); |
| 449 EXPECT_EQ(2u, list.resources.size()); | 427 EXPECT_EQ(2u, list.resources.size()); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 { | 510 { |
| 533 // Resource transfer is only supported with GL textures for now. | 511 // Resource transfer is only supported with GL textures for now. |
| 534 if (GetParam() != ResourceProvider::GLTexture) | 512 if (GetParam() != ResourceProvider::GLTexture) |
| 535 return; | 513 return; |
| 536 | 514 |
| 537 scoped_ptr<OutputSurface> childOutputSurface(FakeOutputSurface::Create3d(Res
ourceProviderContext::create(m_sharedData.get()).PassAs<WebKit::WebGraphicsConte
xt3D>())); | 515 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())); | 516 scoped_ptr<ResourceProvider> childResourceProvider(ResourceProvider::create(
childOutputSurface.get())); |
| 539 | 517 |
| 540 gfx::Size size(1, 1); | 518 gfx::Size size(1, 1); |
| 541 WGC3Denum format = GL_RGBA; | 519 WGC3Denum format = GL_RGBA; |
| 542 int pool = 1; | |
| 543 size_t pixelSize = textureSize(size, format); | 520 size_t pixelSize = textureSize(size, format); |
| 544 ASSERT_EQ(4U, pixelSize); | 521 ASSERT_EQ(4U, pixelSize); |
| 545 | 522 |
| 546 ResourceProvider::ResourceId id = childResourceProvider->createResource(pool
, size, format, ResourceProvider::TextureUsageAny); | 523 ResourceProvider::ResourceId id = childResourceProvider->createResource(size
, format, ResourceProvider::TextureUsageAny); |
| 547 uint8_t data[4] = {1, 2, 3, 4}; | 524 uint8_t data[4] = {1, 2, 3, 4}; |
| 548 gfx::Rect rect(gfx::Point(), size); | 525 gfx::Rect rect(gfx::Point(), size); |
| 549 childResourceProvider->setPixels(id, data, rect, rect, gfx::Vector2d()); | 526 childResourceProvider->setPixels(id, data, rect, rect, gfx::Vector2d()); |
| 550 | 527 |
| 551 int childPool = 2; | 528 int childId = m_resourceProvider->createChild(); |
| 552 int childId = m_resourceProvider->createChild(childPool); | |
| 553 | 529 |
| 554 { | 530 { |
| 555 // Transfer some resource to the parent. | 531 // Transfer some resource to the parent. |
| 556 ResourceProvider::ResourceIdArray resourceIdsToTransfer; | 532 ResourceProvider::ResourceIdArray resourceIdsToTransfer; |
| 557 resourceIdsToTransfer.push_back(id); | 533 resourceIdsToTransfer.push_back(id); |
| 558 TransferableResourceList list; | 534 TransferableResourceList list; |
| 559 childResourceProvider->prepareSendToParent(resourceIdsToTransfer, &list)
; | 535 childResourceProvider->prepareSendToParent(resourceIdsToTransfer, &list)
; |
| 560 EXPECT_NE(0u, list.sync_point); | 536 EXPECT_NE(0u, list.sync_point); |
| 561 EXPECT_EQ(1u, list.resources.size()); | 537 EXPECT_EQ(1u, list.resources.size()); |
| 562 EXPECT_TRUE(childResourceProvider->inUseByConsumer(id)); | 538 EXPECT_TRUE(childResourceProvider->inUseByConsumer(id)); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 // Sampling is only supported for GL textures. | 570 // Sampling is only supported for GL textures. |
| 595 if (GetParam() != ResourceProvider::GLTexture) | 571 if (GetParam() != ResourceProvider::GLTexture) |
| 596 return; | 572 return; |
| 597 | 573 |
| 598 scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_p
tr<WebKit::WebGraphicsContext3D>(new TextureStateTrackingContext))); | 574 scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_p
tr<WebKit::WebGraphicsContext3D>(new TextureStateTrackingContext))); |
| 599 TextureStateTrackingContext* context = static_cast<TextureStateTrackingConte
xt*>(outputSurface->Context3D()); | 575 TextureStateTrackingContext* context = static_cast<TextureStateTrackingConte
xt*>(outputSurface->Context3D()); |
| 600 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu
tSurface.get())); | 576 scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outpu
tSurface.get())); |
| 601 | 577 |
| 602 gfx::Size size(1, 1); | 578 gfx::Size size(1, 1); |
| 603 WGC3Denum format = GL_RGBA; | 579 WGC3Denum format = GL_RGBA; |
| 604 int pool = 1; | |
| 605 int textureId = 1; | 580 int textureId = 1; |
| 606 | 581 |
| 607 // Check that the texture gets created with the right sampler settings. | 582 // Check that the texture gets created with the right sampler settings. |
| 608 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, textureId)); | 583 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, textureId)); |
| 609 EXPECT_CALL(*context, texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL
_LINEAR)); | 584 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)); | 585 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)); | 586 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)); | 587 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); | 588 ResourceProvider::ResourceId id = resourceProvider->createResource(size, for
mat, ResourceProvider::TextureUsageAny); |
| 614 | 589 |
| 615 // Creating a sampler with the default filter should not change any texture | 590 // Creating a sampler with the default filter should not change any texture |
| 616 // parameters. | 591 // parameters. |
| 617 { | 592 { |
| 618 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, textureId)); | 593 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, textureId)); |
| 619 ResourceProvider::ScopedSamplerGL sampler(resourceProvider.get(), id, GL
_TEXTURE_2D, GL_LINEAR); | 594 ResourceProvider::ScopedSamplerGL sampler(resourceProvider.get(), id, GL
_TEXTURE_2D, GL_LINEAR); |
| 620 } | 595 } |
| 621 | 596 |
| 622 // Using a different filter should be reflected in the texture parameters. | 597 // Using a different filter should be reflected in the texture parameters. |
| 623 { | 598 { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 638 Mock::VerifyAndClearExpectations(context); | 613 Mock::VerifyAndClearExpectations(context); |
| 639 } | 614 } |
| 640 | 615 |
| 641 INSTANTIATE_TEST_CASE_P(ResourceProviderTests, | 616 INSTANTIATE_TEST_CASE_P(ResourceProviderTests, |
| 642 ResourceProviderTest, | 617 ResourceProviderTest, |
| 643 ::testing::Values(ResourceProvider::GLTexture, | 618 ::testing::Values(ResourceProvider::GLTexture, |
| 644 ResourceProvider::Bitmap)); | 619 ResourceProvider::Bitmap)); |
| 645 | 620 |
| 646 } // namespace | 621 } // namespace |
| 647 } // namespace cc | 622 } // namespace cc |
| OLD | NEW |