Index: ui/gl/gl_image_memory.cc |
diff --git a/ui/gl/gl_image_memory.cc b/ui/gl/gl_image_memory.cc |
index ca106b7cb2941bdb202e00c0632b40a1cb128a5e..ad429d99b66d5462f1da2610b8552155ff1260e4 100644 |
--- a/ui/gl/gl_image_memory.cc |
+++ b/ui/gl/gl_image_memory.cc |
@@ -17,16 +17,8 @@ |
namespace gfx { |
namespace { |
-bool ValidInternalFormat(unsigned internalformat) { |
- switch (internalformat) { |
- case GL_RGBA: |
- return true; |
- default: |
- return false; |
- } |
-} |
- |
-bool ValidFormat(gfx::GpuMemoryBuffer::Format format) { |
+bool ValidateFormats(gfx::GpuMemoryBuffer::Format format, |
reveman
2015/04/01 13:14:33
Please make this function consistent with the gl_i
Daniele Castagna
2015/04/01 21:58:34
Done.
|
+ unsigned internalformat) { |
switch (format) { |
case gfx::GpuMemoryBuffer::ATC: |
case gfx::GpuMemoryBuffer::ATCIA: |
@@ -35,11 +27,22 @@ bool ValidFormat(gfx::GpuMemoryBuffer::Format format) { |
case gfx::GpuMemoryBuffer::ETC1: |
case gfx::GpuMemoryBuffer::RGBA_8888: |
case gfx::GpuMemoryBuffer::BGRA_8888: |
+ if (internalformat != GL_RGBA) { |
+ LOG(ERROR) << "Invalid internal format " << internalformat |
+ << "for the specified format: " << format; |
+ return false; |
+ } |
+ return true; |
+ case gfx::GpuMemoryBuffer::R_8: |
+ if (internalformat != GL_LUMINANCE && internalformat != GL_R8) { |
+ LOG(ERROR) << "Invalid internal format " << internalformat |
+ << "for the specified format: " << format; |
+ } |
return true; |
case gfx::GpuMemoryBuffer::RGBX_8888: |
+ LOG(ERROR) << "Invalid format: " << format; |
return false; |
} |
- |
NOTREACHED(); |
return false; |
} |
@@ -52,6 +55,7 @@ bool IsCompressedFormat(gfx::GpuMemoryBuffer::Format format) { |
case gfx::GpuMemoryBuffer::DXT5: |
case gfx::GpuMemoryBuffer::ETC1: |
return true; |
+ case gfx::GpuMemoryBuffer::R_8: |
case gfx::GpuMemoryBuffer::RGBA_8888: |
case gfx::GpuMemoryBuffer::BGRA_8888: |
case gfx::GpuMemoryBuffer::RGBX_8888: |
@@ -62,7 +66,8 @@ bool IsCompressedFormat(gfx::GpuMemoryBuffer::Format format) { |
return false; |
} |
-GLenum TextureFormat(gfx::GpuMemoryBuffer::Format format) { |
+GLenum TextureFormat(gfx::GpuMemoryBuffer::Format format, |
+ unsigned internalformat) { |
switch (format) { |
reveman
2015/04/01 13:14:33
can you move this switch (format) statement into a
Daniele Castagna
2015/04/01 21:58:34
Split in two functions TextureFormat and InternalT
|
case gfx::GpuMemoryBuffer::ATC: |
return GL_ATC_RGB_AMD; |
@@ -74,6 +79,9 @@ GLenum TextureFormat(gfx::GpuMemoryBuffer::Format format) { |
return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; |
case gfx::GpuMemoryBuffer::ETC1: |
return GL_ETC1_RGB8_OES; |
+ case gfx::GpuMemoryBuffer::R_8: |
+ DCHECK(internalformat == GL_R8 || internalformat == GL_LUMINANCE); |
+ return internalformat; |
case gfx::GpuMemoryBuffer::RGBA_8888: |
return GL_RGBA; |
case gfx::GpuMemoryBuffer::BGRA_8888: |
@@ -87,14 +95,17 @@ GLenum TextureFormat(gfx::GpuMemoryBuffer::Format format) { |
return 0; |
} |
-GLenum DataFormat(gfx::GpuMemoryBuffer::Format format) { |
- return TextureFormat(format); |
+GLenum DataFormat(gfx::GpuMemoryBuffer::Format format, |
+ unsigned internalformat) { |
reveman
2015/04/01 13:14:33
hm, I'm not a fan of passing internalformat to thi
Daniele Castagna
2015/04/01 21:58:35
I'm afraid DataFormat needs to know about internal
|
+ GLenum data_format = TextureFormat(format, internalformat); |
+ return data_format == GL_R8 ? GL_RED : data_format; |
} |
GLenum DataType(gfx::GpuMemoryBuffer::Format format) { |
switch (format) { |
case gfx::GpuMemoryBuffer::RGBA_8888: |
case gfx::GpuMemoryBuffer::BGRA_8888: |
+ case gfx::GpuMemoryBuffer::R_8: |
return GL_UNSIGNED_BYTE; |
case gfx::GpuMemoryBuffer::ATC: |
case gfx::GpuMemoryBuffer::ATCIA: |
@@ -150,48 +161,35 @@ GLImageMemory::~GLImageMemory() { |
bool GLImageMemory::StrideInBytes(size_t width, |
reveman
2015/04/01 13:14:33
Just make sure this function is consistent with Gp
Daniele Castagna
2015/04/01 21:58:35
If by "make sure this function is consistent" you
|
gfx::GpuMemoryBuffer::Format format, |
size_t* stride_in_bytes) { |
- base::CheckedNumeric<size_t> s = width; |
+ base::CheckedNumeric<size_t> checked_stride = width; |
switch (format) { |
- case gfx::GpuMemoryBuffer::ATCIA: |
- case gfx::GpuMemoryBuffer::DXT5: |
- *stride_in_bytes = width; |
- return true; |
- case gfx::GpuMemoryBuffer::ATC: |
- case gfx::GpuMemoryBuffer::DXT1: |
- case gfx::GpuMemoryBuffer::ETC1: |
+ case GpuMemoryBuffer::R_8: |
+ checked_stride = (checked_stride + 3) % 4; |
+ break; |
+ case GpuMemoryBuffer::ATCIA: |
+ case GpuMemoryBuffer::DXT5: // 'checked_stride' is the same as 'width'. |
+ break; |
+ case GpuMemoryBuffer::ATC: |
+ case GpuMemoryBuffer::DXT1: |
+ case GpuMemoryBuffer::ETC1: |
DCHECK_EQ(width % 2, 0U); |
- s /= 2; |
- if (!s.IsValid()) |
- return false; |
- |
- *stride_in_bytes = s.ValueOrDie(); |
- return true; |
- case gfx::GpuMemoryBuffer::RGBA_8888: |
- case gfx::GpuMemoryBuffer::BGRA_8888: |
- s *= 4; |
- if (!s.IsValid()) |
- return false; |
- |
- *stride_in_bytes = s.ValueOrDie(); |
- return true; |
- case gfx::GpuMemoryBuffer::RGBX_8888: |
- NOTREACHED(); |
- return false; |
+ checked_stride /= 2; |
+ break; |
+ case GpuMemoryBuffer::RGBA_8888: |
+ case GpuMemoryBuffer::RGBX_8888: |
+ case GpuMemoryBuffer::BGRA_8888: |
+ checked_stride *= 4; |
+ break; |
} |
- |
- NOTREACHED(); |
- return false; |
+ if (!checked_stride.IsValid()) |
+ return false; |
+ *stride_in_bytes = checked_stride.ValueOrDie(); |
+ return true; |
} |
bool GLImageMemory::Initialize(const unsigned char* memory, |
gfx::GpuMemoryBuffer::Format format) { |
- if (!ValidInternalFormat(internalformat_)) { |
reveman
2015/04/01 13:14:33
Please make this function consistent with GLImageL
Daniele Castagna
2015/04/01 21:58:34
Done.
|
- LOG(ERROR) << "Invalid internalformat: " << internalformat_; |
- return false; |
- } |
- |
- if (!ValidFormat(format)) { |
- LOG(ERROR) << "Invalid format: " << format; |
+ if (!ValidateFormats(format, internalformat_)) { |
return false; |
} |
@@ -256,14 +254,15 @@ bool GLImageMemory::CopyTexImage(unsigned target) { |
0, // x-offset |
0, // y-offset |
size_.width(), size_.height(), |
- DataFormat(format_), SizeInBytes(size_, format_), |
- memory_); |
+ DataFormat(format_, internalformat_), |
+ SizeInBytes(size_, format_), memory_); |
} else { |
glTexSubImage2D(target, 0, // level |
0, // x |
0, // y |
- size_.width(), size_.height(), DataFormat(format_), |
- DataType(format_), memory_); |
+ size_.width(), size_.height(), |
+ DataFormat(format_, internalformat_), DataType(format_), |
+ memory_); |
} |
return true; |
@@ -316,19 +315,17 @@ void GLImageMemory::DoBindTexImage(unsigned target) { |
if (IsCompressedFormat(format_)) { |
glCompressedTexImage2D(GL_TEXTURE_2D, |
0, // mip level |
- TextureFormat(format_), size_.width(), |
- size_.height(), |
+ TextureFormat(format_, internalformat_), |
+ size_.width(), size_.height(), |
0, // border |
SizeInBytes(size_, format_), memory_); |
} else { |
glTexImage2D(GL_TEXTURE_2D, |
0, // mip level |
- TextureFormat(format_), |
- size_.width(), |
+ TextureFormat(format_, internalformat_), size_.width(), |
size_.height(), |
0, // border |
- DataFormat(format_), |
- DataType(format_), |
+ DataFormat(format_, internalformat_), DataType(format_), |
memory_); |
} |
} |
@@ -353,18 +350,15 @@ void GLImageMemory::DoBindTexImage(unsigned target) { |
0, // x-offset |
0, // y-offset |
size_.width(), size_.height(), |
- DataFormat(format_), |
- SizeInBytes(size_, format_), |
- memory_); |
+ DataFormat(format_, internalformat_), |
+ SizeInBytes(size_, format_), memory_); |
} else { |
glTexSubImage2D(GL_TEXTURE_2D, |
0, // mip level |
0, // x-offset |
0, // y-offset |
- size_.width(), |
- size_.height(), |
- DataFormat(format_), |
- DataType(format_), |
+ size_.width(), size_.height(), |
+ DataFormat(format_, internalformat_), DataType(format_), |
memory_); |
} |
} |
@@ -379,20 +373,17 @@ void GLImageMemory::DoBindTexImage(unsigned target) { |
if (IsCompressedFormat(format_)) { |
glCompressedTexImage2D(target, |
0, // mip level |
- TextureFormat(format_), size_.width(), |
- size_.height(), |
+ TextureFormat(format_, internalformat_), |
+ size_.width(), size_.height(), |
0, // border |
SizeInBytes(size_, format_), memory_); |
} else { |
- glTexImage2D(target, |
- 0, // mip level |
- TextureFormat(format_), |
- size_.width(), |
- size_.height(), |
- 0, // border |
- DataFormat(format_), |
- DataType(format_), |
- memory_); |
+ glTexImage2D( |
+ target, |
+ 0, // mip level |
+ TextureFormat(format_, internalformat_), size_.width(), size_.height(), |
+ 0, // border |
+ DataFormat(format_, internalformat_), DataType(format_), memory_); |
} |
} |