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..674fbd4ebc20d3e4773de7ad6427d5db81a18df5 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, ResourceFormat 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(RGBA_8888), |
+ filter(GL_NEAREST_MIPMAP_LINEAR) {} |
- void Reallocate(gfx::Size size, WGC3Denum format) { |
+ void Reallocate(gfx::Size size, ResourceFormat format) { |
this->size = size; |
this->format = format; |
this->data.reset(new uint8_t[TextureSize(size, format)]); |
} |
gfx::Size size; |
- WGC3Denum format; |
+ ResourceFormat 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,7 @@ class ResourceProviderContext : public TestWebGraphicsContext3D { |
mailbox, last_waited_sync_point_); |
} |
- void GetPixels(gfx::Size size, WGC3Denum format, uint8_t* pixels) { |
+ void GetPixels(gfx::Size size, ResourceFormat format, uint8_t* pixels) { |
ASSERT_TRUE(current_texture_); |
scoped_refptr<Texture> texture = textures_[current_texture_]; |
ASSERT_TRUE(texture.get()); |
@@ -294,7 +297,16 @@ class ResourceProviderContext : public TestWebGraphicsContext3D { |
ASSERT_TRUE(current_texture_); |
scoped_refptr<Texture> texture = textures_[current_texture_]; |
ASSERT_TRUE(texture.get()); |
- texture->Reallocate(size, format); |
+ ResourceFormat texture_format = RGBA_8888; |
+ switch (format) { |
+ case GL_RGBA: |
+ texture_format = RGBA_8888; |
+ break; |
+ case GL_BGRA_EXT: |
+ texture_format = BGRA_8888; |
+ break; |
+ } |
+ texture->Reallocate(size, texture_format); |
} |
void SetPixels(int xoffset, |
@@ -339,7 +351,7 @@ void GetResourcePixels(ResourceProvider* resource_provider, |
ResourceProviderContext* context, |
ResourceProvider::ResourceId id, |
gfx::Size size, |
- WGC3Denum format, |
+ ResourceFormat format, |
uint8_t* pixels) { |
switch (resource_provider->default_resource_type()) { |
case ResourceProvider::GLTexture: { |
@@ -427,12 +439,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; |
+ ResourceFormat format = 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 +471,12 @@ TEST_P(ResourceProviderTest, Basic) { |
TEST_P(ResourceProviderTest, Upload) { |
gfx::Size size(2, 2); |
- WGC3Denum format = GL_RGBA; |
+ ResourceFormat format = 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 +555,18 @@ TEST_P(ResourceProviderTest, TransferResources) { |
ResourceProvider::Create(child_output_surface.get(), 0)); |
gfx::Size size(1, 1); |
- WGC3Denum format = GL_RGBA; |
+ ResourceFormat format = 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 +691,12 @@ TEST_P(ResourceProviderTest, DeleteTransferredResources) { |
ResourceProvider::Create(child_output_surface.get(), 0)); |
gfx::Size size(1, 1); |
- WGC3Denum format = GL_RGBA; |
+ ResourceFormat format = 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 +754,12 @@ TEST_P(ResourceProviderTest, TextureFilters) { |
ResourceProvider::Create(child_output_surface.get(), 0)); |
gfx::Size size(1, 1); |
- WGC3Denum format = GL_RGBA; |
+ ResourceFormat format = 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 +867,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), 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 +914,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), 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 +1107,7 @@ TEST_P(ResourceProviderTest, ScopedSampler) { |
ResourceProvider::Create(output_surface.get(), 0)); |
gfx::Size size(1, 1); |
- WGC3Denum format = GL_RGBA; |
+ ResourceFormat format = RGBA_8888; |
int texture_id = 1; |
// Check that the texture gets created with the right sampler settings. |
@@ -1114,7 +1128,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 +1184,12 @@ TEST_P(ResourceProviderTest, ManagedResource) { |
ResourceProvider::Create(output_surface.get(), 0)); |
gfx::Size size(1, 1); |
- WGC3Denum format = GL_RGBA; |
+ ResourceFormat format = 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 +1229,19 @@ TEST_P(ResourceProviderTest, TextureWrapMode) { |
ResourceProvider::Create(output_surface.get(), 0)); |
gfx::Size size(1, 1); |
- WGC3Denum format = GL_RGBA; |
+ ResourceFormat format = 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 +1505,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; |
+ ResourceFormat format = 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 +1525,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 +1540,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 +1571,7 @@ TEST_P(ResourceProviderTest, PixelBuffer_GLTexture) { |
CHECK(output_surface->BindToClient(&output_surface_client)); |
gfx::Size size(2, 2); |
- WGC3Denum format = GL_RGBA; |
+ ResourceFormat format = RGBA_8888; |
ResourceProvider::ResourceId id = 0; |
int texture_id = 123; |
@@ -1562,7 +1579,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 +1608,7 @@ TEST_P(ResourceProviderTest, PixelBuffer_Bitmap) { |
CHECK(output_surface->BindToClient(&output_surface_client)); |
gfx::Size size(1, 1); |
- WGC3Denum format = GL_RGBA; |
+ ResourceFormat format = RGBA_8888; |
ResourceProvider::ResourceId id = 0; |
const uint32_t kBadBeef = 0xbadbeef; |
@@ -1599,7 +1616,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 +1654,7 @@ TEST_P(ResourceProviderTest, ForcingAsyncUploadToComplete) { |
CHECK(output_surface->BindToClient(&output_surface_client)); |
gfx::Size size(2, 2); |
- WGC3Denum format = GL_RGBA; |
+ ResourceFormat format = RGBA_8888; |
ResourceProvider::ResourceId id = 0; |
int texture_id = 123; |
@@ -1645,7 +1662,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 +1695,7 @@ TEST_P(ResourceProviderTest, PixelBufferLostContext) { |
CHECK(output_surface->BindToClient(&output_surface_client)); |
gfx::Size size(2, 2); |
- WGC3Denum format = GL_RGBA; |
+ ResourceFormat format = RGBA_8888; |
ResourceProvider::ResourceId id = 0; |
int texture_id = 123; |
@@ -1688,7 +1705,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 +1732,7 @@ TEST_P(ResourceProviderTest, Image_GLTexture) { |
const int kWidth = 2; |
const int kHeight = 2; |
gfx::Size size(kWidth, kHeight); |
- WGC3Denum format = GL_RGBA; |
+ ResourceFormat format = RGBA_8888; |
ResourceProvider::ResourceId id = 0; |
const unsigned kTextureId = 123u; |
const unsigned kImageId = 234u; |
@@ -1724,7 +1741,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 +1804,7 @@ TEST_P(ResourceProviderTest, Image_Bitmap) { |
CHECK(output_surface->BindToClient(&output_surface_client)); |
gfx::Size size(1, 1); |
- WGC3Denum format = GL_RGBA; |
+ ResourceFormat format = RGBA_8888; |
ResourceProvider::ResourceId id = 0; |
const uint32_t kBadBeef = 0xbadbeef; |
@@ -1795,7 +1812,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; |