| Index: cc/resources/resource_provider_unittest.cc
|
| diff --git a/cc/resources/resource_provider_unittest.cc b/cc/resources/resource_provider_unittest.cc
|
| index 3f786ef8277b8208dd818fea418cda8acaef04cb..88e0a5b847189e0ef0c397ef31cff4d70a948513 100644
|
| --- a/cc/resources/resource_provider_unittest.cc
|
| +++ b/cc/resources/resource_provider_unittest.cc
|
| @@ -40,7 +40,7 @@ using WebKit::WebGLId;
|
| namespace cc {
|
| namespace {
|
|
|
| -size_t TextureSize(gfx::Size size, WGC3Denum format) {
|
| +size_t TextureSize(gfx::Size size, ResourceProvider::Format format) {
|
| unsigned int components_per_pixel = 4;
|
| unsigned int bytes_per_component = 1;
|
| return size.width() * size.height() * components_per_pixel *
|
| @@ -48,16 +48,17 @@ size_t TextureSize(gfx::Size size, WGC3Denum format) {
|
| }
|
|
|
| struct Texture : public base::RefCounted<Texture> {
|
| - Texture() : format(0), filter(GL_NEAREST_MIPMAP_LINEAR) {}
|
| + Texture() : format(ResourceProvider::RGBA_8888),
|
| + filter(GL_NEAREST_MIPMAP_LINEAR) {}
|
|
|
| - void Reallocate(gfx::Size size, WGC3Denum format) {
|
| + void Reallocate(gfx::Size size, ResourceProvider::Format format) {
|
| this->size = size;
|
| this->format = format;
|
| this->data.reset(new uint8_t[TextureSize(size, format)]);
|
| }
|
|
|
| gfx::Size size;
|
| - WGC3Denum format;
|
| + ResourceProvider::Format format;
|
| WGC3Denum filter;
|
| scoped_ptr<uint8_t[]> data;
|
|
|
| @@ -220,7 +221,9 @@ class ResourceProviderContext : public TestWebGraphicsContext3D {
|
| ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target);
|
| ASSERT_FALSE(level);
|
| ASSERT_TRUE(textures_[current_texture_].get());
|
| - ASSERT_EQ(textures_[current_texture_]->format, format);
|
| + ASSERT_EQ(
|
| + ResourceProvider::GetGLDataFormat(textures_[current_texture_]->format),
|
| + format);
|
| ASSERT_EQ(static_cast<unsigned>(GL_UNSIGNED_BYTE), type);
|
| ASSERT_TRUE(pixels);
|
| SetPixels(xoffset, yoffset, width, height, pixels);
|
| @@ -263,7 +266,8 @@ class ResourceProviderContext : public TestWebGraphicsContext3D {
|
| mailbox, last_waited_sync_point_);
|
| }
|
|
|
| - void GetPixels(gfx::Size size, WGC3Denum format, uint8_t* pixels) {
|
| + void GetPixels(
|
| + gfx::Size size, ResourceProvider::Format format, uint8_t* pixels) {
|
| ASSERT_TRUE(current_texture_);
|
| scoped_refptr<Texture> texture = textures_[current_texture_];
|
| ASSERT_TRUE(texture.get());
|
| @@ -294,7 +298,16 @@ class ResourceProviderContext : public TestWebGraphicsContext3D {
|
| ASSERT_TRUE(current_texture_);
|
| scoped_refptr<Texture> texture = textures_[current_texture_];
|
| ASSERT_TRUE(texture.get());
|
| - texture->Reallocate(size, format);
|
| + ResourceProvider::Format texture_format = ResourceProvider::RGBA_8888;
|
| + switch (format) {
|
| + case GL_RGBA:
|
| + texture_format = ResourceProvider::RGBA_8888;
|
| + break;
|
| + case GL_BGRA_EXT:
|
| + texture_format = ResourceProvider::BGRA_8888;
|
| + break;
|
| + }
|
| + texture->Reallocate(size, texture_format);
|
| }
|
|
|
| void SetPixels(int xoffset,
|
| @@ -339,7 +352,7 @@ void GetResourcePixels(ResourceProvider* resource_provider,
|
| ResourceProviderContext* context,
|
| ResourceProvider::ResourceId id,
|
| gfx::Size size,
|
| - WGC3Denum format,
|
| + ResourceProvider::Format format,
|
| uint8_t* pixels) {
|
| switch (resource_provider->default_resource_type()) {
|
| case ResourceProvider::GLTexture: {
|
| @@ -427,12 +440,12 @@ void CheckCreateResource(ResourceProvider::ResourceType expected_default_type,
|
| DCHECK_EQ(expected_default_type, resource_provider->default_resource_type());
|
|
|
| gfx::Size size(1, 1);
|
| - WGC3Denum format = GL_RGBA;
|
| + ResourceProvider::Format format = ResourceProvider::RGBA_8888;
|
| size_t pixel_size = TextureSize(size, format);
|
| ASSERT_EQ(4U, pixel_size);
|
|
|
| ResourceProvider::ResourceId id = resource_provider->CreateResource(
|
| - size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny);
|
| + size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
|
| EXPECT_EQ(1, static_cast<int>(resource_provider->num_resources()));
|
| if (expected_default_type == ResourceProvider::GLTexture)
|
| EXPECT_EQ(0, context->texture_count());
|
| @@ -459,12 +472,12 @@ TEST_P(ResourceProviderTest, Basic) {
|
|
|
| TEST_P(ResourceProviderTest, Upload) {
|
| gfx::Size size(2, 2);
|
| - WGC3Denum format = GL_RGBA;
|
| + ResourceProvider::Format format = ResourceProvider::RGBA_8888;
|
| size_t pixel_size = TextureSize(size, format);
|
| ASSERT_EQ(16U, pixel_size);
|
|
|
| ResourceProvider::ResourceId id = resource_provider_->CreateResource(
|
| - size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny);
|
| + size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
|
|
|
| uint8_t image[16] = { 0 };
|
| gfx::Rect image_rect(size);
|
| @@ -543,18 +556,18 @@ TEST_P(ResourceProviderTest, TransferResources) {
|
| ResourceProvider::Create(child_output_surface.get(), 0));
|
|
|
| gfx::Size size(1, 1);
|
| - WGC3Denum format = GL_RGBA;
|
| + ResourceProvider::Format format = ResourceProvider::RGBA_8888;
|
| size_t pixel_size = TextureSize(size, format);
|
| ASSERT_EQ(4U, pixel_size);
|
|
|
| ResourceProvider::ResourceId id1 = child_resource_provider->CreateResource(
|
| - size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny);
|
| + size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
|
| uint8_t data1[4] = { 1, 2, 3, 4 };
|
| gfx::Rect rect(size);
|
| child_resource_provider->SetPixels(id1, data1, rect, rect, gfx::Vector2d());
|
|
|
| ResourceProvider::ResourceId id2 = child_resource_provider->CreateResource(
|
| - size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny);
|
| + size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
|
| uint8_t data2[4] = { 5, 5, 5, 5 };
|
| child_resource_provider->SetPixels(id2, data2, rect, rect, gfx::Vector2d());
|
|
|
| @@ -679,12 +692,12 @@ TEST_P(ResourceProviderTest, DeleteTransferredResources) {
|
| ResourceProvider::Create(child_output_surface.get(), 0));
|
|
|
| gfx::Size size(1, 1);
|
| - WGC3Denum format = GL_RGBA;
|
| + ResourceProvider::Format format = ResourceProvider::RGBA_8888;
|
| size_t pixel_size = TextureSize(size, format);
|
| ASSERT_EQ(4U, pixel_size);
|
|
|
| ResourceProvider::ResourceId id = child_resource_provider->CreateResource(
|
| - size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny);
|
| + size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
|
| uint8_t data[4] = { 1, 2, 3, 4 };
|
| gfx::Rect rect(size);
|
| child_resource_provider->SetPixels(id, data, rect, rect, gfx::Vector2d());
|
| @@ -742,12 +755,12 @@ TEST_P(ResourceProviderTest, TextureFilters) {
|
| ResourceProvider::Create(child_output_surface.get(), 0));
|
|
|
| gfx::Size size(1, 1);
|
| - WGC3Denum format = GL_RGBA;
|
| + ResourceProvider::Format format = ResourceProvider::RGBA_8888;
|
| size_t pixel_size = TextureSize(size, format);
|
| ASSERT_EQ(4U, pixel_size);
|
|
|
| ResourceProvider::ResourceId id = child_resource_provider->CreateResource(
|
| - size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny);
|
| + size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
|
| uint8_t data[4] = { 1, 2, 3, 4 };
|
| gfx::Rect rect(size);
|
| child_resource_provider->SetPixels(id, data, rect, rect, gfx::Vector2d());
|
| @@ -855,7 +868,8 @@ TEST_P(ResourceProviderTest, TransferMailboxResources) {
|
| context()->bindTexture(GL_TEXTURE_2D, other_texture);
|
| context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
|
| uint8_t test_data[4] = { 0 };
|
| - context()->GetPixels(gfx::Size(1, 1), GL_RGBA, test_data);
|
| + context()->GetPixels(
|
| + gfx::Size(1, 1), ResourceProvider::RGBA_8888, test_data);
|
| EXPECT_EQ(0, memcmp(data, test_data, sizeof(data)));
|
| context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
|
| context()->deleteTexture(other_texture);
|
| @@ -901,7 +915,8 @@ TEST_P(ResourceProviderTest, TransferMailboxResources) {
|
| context()->bindTexture(GL_TEXTURE_2D, other_texture);
|
| context()->consumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
|
| uint8_t test_data[4] = { 0 };
|
| - context()->GetPixels(gfx::Size(1, 1), GL_RGBA, test_data);
|
| + context()->GetPixels(
|
| + gfx::Size(1, 1), ResourceProvider::RGBA_8888, test_data);
|
| EXPECT_EQ(0, memcmp(data, test_data, sizeof(data)));
|
| context()->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
|
| context()->deleteTexture(other_texture);
|
| @@ -1093,7 +1108,7 @@ TEST_P(ResourceProviderTest, ScopedSampler) {
|
| ResourceProvider::Create(output_surface.get(), 0));
|
|
|
| gfx::Size size(1, 1);
|
| - WGC3Denum format = GL_RGBA;
|
| + ResourceProvider::Format format = ResourceProvider::RGBA_8888;
|
| int texture_id = 1;
|
|
|
| // Check that the texture gets created with the right sampler settings.
|
| @@ -1114,7 +1129,7 @@ TEST_P(ResourceProviderTest, ScopedSampler) {
|
| GL_TEXTURE_POOL_CHROMIUM,
|
| GL_TEXTURE_POOL_UNMANAGED_CHROMIUM));
|
| ResourceProvider::ResourceId id = resource_provider->CreateResource(
|
| - size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny);
|
| + size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
|
| resource_provider->AllocateForTesting(id);
|
|
|
| // Creating a sampler with the default filter should not change any texture
|
| @@ -1170,12 +1185,12 @@ TEST_P(ResourceProviderTest, ManagedResource) {
|
| ResourceProvider::Create(output_surface.get(), 0));
|
|
|
| gfx::Size size(1, 1);
|
| - WGC3Denum format = GL_RGBA;
|
| + ResourceProvider::Format format = ResourceProvider::RGBA_8888;
|
| int texture_id = 1;
|
|
|
| // Check that the texture gets created with the right sampler settings.
|
| ResourceProvider::ResourceId id = resource_provider->CreateManagedResource(
|
| - size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny);
|
| + size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
|
| EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id));
|
| EXPECT_CALL(*context,
|
| texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
|
| @@ -1215,16 +1230,19 @@ TEST_P(ResourceProviderTest, TextureWrapMode) {
|
| ResourceProvider::Create(output_surface.get(), 0));
|
|
|
| gfx::Size size(1, 1);
|
| - WGC3Denum format = GL_RGBA;
|
| + ResourceProvider::Format format = ResourceProvider::RGBA_8888;
|
| int texture_id = 1;
|
| GLenum texture_pool = GL_TEXTURE_POOL_UNMANAGED_CHROMIUM;
|
|
|
| for (int i = 0; i < 2; ++i) {
|
| GLint wrap_mode = i ? GL_CLAMP_TO_EDGE : GL_REPEAT;
|
| // Check that the texture gets created with the right sampler settings.
|
| - ResourceProvider::ResourceId id = resource_provider->CreateGLTexture(
|
| - size, format, texture_pool, wrap_mode,
|
| - ResourceProvider::TextureUsageAny);
|
| + ResourceProvider::ResourceId id =
|
| + resource_provider->CreateGLTexture(size,
|
| + texture_pool,
|
| + wrap_mode,
|
| + ResourceProvider::TextureUsageAny,
|
| + format);
|
| EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id));
|
| EXPECT_CALL(*context,
|
| texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
|
| @@ -1488,14 +1506,14 @@ TEST_P(ResourceProviderTest, TextureAllocation) {
|
| gfx::Size size(2, 2);
|
| gfx::Vector2d offset(0, 0);
|
| gfx::Rect rect(0, 0, 2, 2);
|
| - WGC3Denum format = GL_RGBA;
|
| + ResourceProvider::Format format = ResourceProvider::RGBA_8888;
|
| ResourceProvider::ResourceId id = 0;
|
| uint8_t pixels[16] = { 0 };
|
| int texture_id = 123;
|
|
|
| // Lazy allocation. Don't allocate when creating the resource.
|
| id = resource_provider->CreateResource(
|
| - size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny);
|
| + size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
|
|
|
| EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id));
|
| EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1);
|
| @@ -1508,7 +1526,7 @@ TEST_P(ResourceProviderTest, TextureAllocation) {
|
|
|
| // Do allocate when we set the pixels.
|
| id = resource_provider->CreateResource(
|
| - size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny);
|
| + size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
|
|
|
| EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id));
|
| EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(3);
|
| @@ -1523,7 +1541,7 @@ TEST_P(ResourceProviderTest, TextureAllocation) {
|
|
|
| // Same for async version.
|
| id = resource_provider->CreateResource(
|
| - size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny);
|
| + size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
|
| resource_provider->AcquirePixelBuffer(id);
|
|
|
| EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id));
|
| @@ -1554,7 +1572,7 @@ TEST_P(ResourceProviderTest, PixelBuffer_GLTexture) {
|
| CHECK(output_surface->BindToClient(&output_surface_client));
|
|
|
| gfx::Size size(2, 2);
|
| - WGC3Denum format = GL_RGBA;
|
| + ResourceProvider::Format format = ResourceProvider::RGBA_8888;
|
| ResourceProvider::ResourceId id = 0;
|
| int texture_id = 123;
|
|
|
| @@ -1562,7 +1580,7 @@ TEST_P(ResourceProviderTest, PixelBuffer_GLTexture) {
|
| ResourceProvider::Create(output_surface.get(), 0));
|
|
|
| id = resource_provider->CreateResource(
|
| - size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny);
|
| + size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
|
| resource_provider->AcquirePixelBuffer(id);
|
|
|
| EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id));
|
| @@ -1591,7 +1609,7 @@ TEST_P(ResourceProviderTest, PixelBuffer_Bitmap) {
|
| CHECK(output_surface->BindToClient(&output_surface_client));
|
|
|
| gfx::Size size(1, 1);
|
| - WGC3Denum format = GL_RGBA;
|
| + ResourceProvider::Format format = ResourceProvider::RGBA_8888;
|
| ResourceProvider::ResourceId id = 0;
|
| const uint32_t kBadBeef = 0xbadbeef;
|
|
|
| @@ -1599,7 +1617,7 @@ TEST_P(ResourceProviderTest, PixelBuffer_Bitmap) {
|
| ResourceProvider::Create(output_surface.get(), 0));
|
|
|
| id = resource_provider->CreateResource(
|
| - size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny);
|
| + size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
|
| resource_provider->AcquirePixelBuffer(id);
|
|
|
| void* data = resource_provider->MapPixelBuffer(id);
|
| @@ -1637,7 +1655,7 @@ TEST_P(ResourceProviderTest, ForcingAsyncUploadToComplete) {
|
| CHECK(output_surface->BindToClient(&output_surface_client));
|
|
|
| gfx::Size size(2, 2);
|
| - WGC3Denum format = GL_RGBA;
|
| + ResourceProvider::Format format = ResourceProvider::RGBA_8888;
|
| ResourceProvider::ResourceId id = 0;
|
| int texture_id = 123;
|
|
|
| @@ -1645,7 +1663,7 @@ TEST_P(ResourceProviderTest, ForcingAsyncUploadToComplete) {
|
| ResourceProvider::Create(output_surface.get(), 0));
|
|
|
| id = resource_provider->CreateResource(
|
| - size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny);
|
| + size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
|
| resource_provider->AcquirePixelBuffer(id);
|
|
|
| EXPECT_CALL(*context, createTexture()).WillOnce(Return(texture_id));
|
| @@ -1678,7 +1696,7 @@ TEST_P(ResourceProviderTest, PixelBufferLostContext) {
|
| CHECK(output_surface->BindToClient(&output_surface_client));
|
|
|
| gfx::Size size(2, 2);
|
| - WGC3Denum format = GL_RGBA;
|
| + ResourceProvider::Format format = ResourceProvider::RGBA_8888;
|
| ResourceProvider::ResourceId id = 0;
|
| int texture_id = 123;
|
|
|
| @@ -1688,7 +1706,7 @@ TEST_P(ResourceProviderTest, PixelBufferLostContext) {
|
| EXPECT_CALL(*context, createTexture()).WillRepeatedly(Return(texture_id));
|
|
|
| id = resource_provider->CreateResource(
|
| - size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny);
|
| + size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
|
| context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
|
| GL_INNOCENT_CONTEXT_RESET_ARB);
|
| resource_provider->AcquirePixelBuffer(id);
|
| @@ -1715,7 +1733,7 @@ TEST_P(ResourceProviderTest, Image_GLTexture) {
|
| const int kWidth = 2;
|
| const int kHeight = 2;
|
| gfx::Size size(kWidth, kHeight);
|
| - WGC3Denum format = GL_RGBA;
|
| + ResourceProvider::Format format = ResourceProvider::RGBA_8888;
|
| ResourceProvider::ResourceId id = 0;
|
| const unsigned kTextureId = 123u;
|
| const unsigned kImageId = 234u;
|
| @@ -1724,7 +1742,7 @@ TEST_P(ResourceProviderTest, Image_GLTexture) {
|
| ResourceProvider::Create(output_surface.get(), 0));
|
|
|
| id = resource_provider->CreateResource(
|
| - size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny);
|
| + size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
|
| EXPECT_CALL(*context, createImageCHROMIUM(kWidth, kHeight, GL_RGBA8_OES))
|
| .WillOnce(Return(kImageId))
|
| .RetiresOnSaturation();
|
| @@ -1787,7 +1805,7 @@ TEST_P(ResourceProviderTest, Image_Bitmap) {
|
| CHECK(output_surface->BindToClient(&output_surface_client));
|
|
|
| gfx::Size size(1, 1);
|
| - WGC3Denum format = GL_RGBA;
|
| + ResourceProvider::Format format = ResourceProvider::RGBA_8888;
|
| ResourceProvider::ResourceId id = 0;
|
| const uint32_t kBadBeef = 0xbadbeef;
|
|
|
| @@ -1795,7 +1813,7 @@ TEST_P(ResourceProviderTest, Image_Bitmap) {
|
| ResourceProvider::Create(output_surface.get(), 0));
|
|
|
| id = resource_provider->CreateResource(
|
| - size, format, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny);
|
| + size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format);
|
| resource_provider->AcquireImage(id);
|
|
|
| const int kStride = 0;
|
|
|