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/resources/resource_provider.h" | 5 #include "cc/resources/resource_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
515 size_t pixel_size = TextureSizeBytes(size, format); | 515 size_t pixel_size = TextureSizeBytes(size, format); |
516 ASSERT_EQ(4U, pixel_size); | 516 ASSERT_EQ(4U, pixel_size); |
517 | 517 |
518 ResourceProvider::ResourceId id = resource_provider->CreateResource( | 518 ResourceProvider::ResourceId id = resource_provider->CreateResource( |
519 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); | 519 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); |
520 EXPECT_EQ(1, static_cast<int>(resource_provider->num_resources())); | 520 EXPECT_EQ(1, static_cast<int>(resource_provider->num_resources())); |
521 if (expected_default_type == ResourceProvider::GLTexture) | 521 if (expected_default_type == ResourceProvider::GLTexture) |
522 EXPECT_EQ(0u, context->NumTextures()); | 522 EXPECT_EQ(0u, context->NumTextures()); |
523 | 523 |
524 uint8_t data[4] = { 1, 2, 3, 4 }; | 524 uint8_t data[4] = { 1, 2, 3, 4 }; |
525 gfx::Rect rect(size); | 525 resource_provider->CopyToResource(id, data, size); |
526 resource_provider->SetPixels(id, data, rect, rect, gfx::Vector2d()); | |
527 if (expected_default_type == ResourceProvider::GLTexture) | 526 if (expected_default_type == ResourceProvider::GLTexture) |
528 EXPECT_EQ(1u, context->NumTextures()); | 527 EXPECT_EQ(1u, context->NumTextures()); |
529 | 528 |
530 uint8_t result[4] = { 0 }; | 529 uint8_t result[4] = { 0 }; |
531 GetResourcePixels(resource_provider, context, id, size, format, result); | 530 GetResourcePixels(resource_provider, context, id, size, format, result); |
532 EXPECT_EQ(0, memcmp(data, result, pixel_size)); | 531 EXPECT_EQ(0, memcmp(data, result, pixel_size)); |
533 | 532 |
534 resource_provider->DeleteResource(id); | 533 resource_provider->DeleteResource(id); |
535 EXPECT_EQ(0, static_cast<int>(resource_provider->num_resources())); | 534 EXPECT_EQ(0, static_cast<int>(resource_provider->num_resources())); |
536 if (expected_default_type == ResourceProvider::GLTexture) | 535 if (expected_default_type == ResourceProvider::GLTexture) |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
601 | 600 |
602 uint8_t expected[16] = { 0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3 }; | 601 uint8_t expected[16] = { 0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3 }; |
603 GetResourcePixels( | 602 GetResourcePixels( |
604 resource_provider_.get(), context(), id, size, format, result); | 603 resource_provider_.get(), context(), id, size, format, result); |
605 EXPECT_EQ(0, memcmp(expected, result, pixel_size)); | 604 EXPECT_EQ(0, memcmp(expected, result, pixel_size)); |
606 } | 605 } |
607 | 606 |
608 resource_provider_->DeleteResource(id); | 607 resource_provider_->DeleteResource(id); |
609 } | 608 } |
610 | 609 |
610 TEST_P(ResourceProviderTest, SimpleUpload) { | |
enne (OOO)
2015/02/19 01:01:27
Would it make sense to test bitmap and ETC1 resour
danakj
2015/02/19 01:03:56
Hm!
Bitmap should be covered by TEST_P-ness. But
| |
611 gfx::Size size(2, 2); | |
612 ResourceFormat format = RGBA_8888; | |
613 size_t pixel_size = TextureSizeBytes(size, format); | |
614 ASSERT_EQ(16U, pixel_size); | |
615 | |
616 ResourceProvider::ResourceId id = resource_provider_->CreateResource( | |
617 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); | |
618 | |
619 uint8_t image[16] = {0}; | |
620 resource_provider_->CopyToResource(id, image, size); | |
621 { | |
622 uint8_t result[16] = {0}; | |
623 uint8_t expected[16] = {0}; | |
624 GetResourcePixels(resource_provider_.get(), context(), id, size, format, | |
625 result); | |
626 EXPECT_EQ(0, memcmp(expected, result, pixel_size)); | |
627 } | |
628 | |
629 for (uint8_t i = 0; i < pixel_size; ++i) | |
630 image[i] = i; | |
631 resource_provider_->CopyToResource(id, image, size); | |
632 { | |
633 uint8_t result[16] = {0}; | |
634 uint8_t expected[16] = { | |
635 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; | |
636 GetResourcePixels(resource_provider_.get(), context(), id, size, format, | |
637 result); | |
638 EXPECT_EQ(0, memcmp(expected, result, pixel_size)); | |
639 } | |
640 } | |
641 | |
611 TEST_P(ResourceProviderTest, TransferGLResources) { | 642 TEST_P(ResourceProviderTest, TransferGLResources) { |
612 if (GetParam() != ResourceProvider::GLTexture) | 643 if (GetParam() != ResourceProvider::GLTexture) |
613 return; | 644 return; |
614 gfx::Size size(1, 1); | 645 gfx::Size size(1, 1); |
615 ResourceFormat format = RGBA_8888; | 646 ResourceFormat format = RGBA_8888; |
616 size_t pixel_size = TextureSizeBytes(size, format); | 647 size_t pixel_size = TextureSizeBytes(size, format); |
617 ASSERT_EQ(4U, pixel_size); | 648 ASSERT_EQ(4U, pixel_size); |
618 | 649 |
619 ResourceProvider::ResourceId id1 = child_resource_provider_->CreateResource( | 650 ResourceProvider::ResourceId id1 = child_resource_provider_->CreateResource( |
620 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); | 651 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); |
(...skipping 3084 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3705 resource_provider->AllocateForTesting(id); | 3736 resource_provider->AllocateForTesting(id); |
3706 Mock::VerifyAndClearExpectations(context); | 3737 Mock::VerifyAndClearExpectations(context); |
3707 | 3738 |
3708 DCHECK_EQ(10u, context->PeekTextureId()); | 3739 DCHECK_EQ(10u, context->PeekTextureId()); |
3709 resource_provider->DeleteResource(id); | 3740 resource_provider->DeleteResource(id); |
3710 } | 3741 } |
3711 } | 3742 } |
3712 | 3743 |
3713 } // namespace | 3744 } // namespace |
3714 } // namespace cc | 3745 } // namespace cc |
OLD | NEW |