Index: ui/gl/gl_image_memory.cc |
diff --git a/ui/gl/gl_image_memory.cc b/ui/gl/gl_image_memory.cc |
index d79a753fb846dc1eac767ab691bc7b3009a55c50..a752940615fd9a6b7cb10bc6f2772468fbd63050 100644 |
--- a/ui/gl/gl_image_memory.cc |
+++ b/ui/gl/gl_image_memory.cc |
@@ -17,60 +17,68 @@ |
namespace gfx { |
namespace { |
-bool ValidFormat(unsigned internalformat) { |
+bool ValidInternalFormat(unsigned internalformat) { |
switch (internalformat) { |
- case GL_BGRA8_EXT: |
- case GL_RGBA8_OES: |
+ case GL_RGBA: |
return true; |
default: |
return false; |
} |
} |
-GLenum TextureFormat(unsigned internalformat) { |
- switch (internalformat) { |
- case GL_BGRA8_EXT: |
- return GL_BGRA_EXT; |
- case GL_RGBA8_OES: |
+bool ValidFormat(gfx::GpuMemoryBuffer::Format format) { |
+ switch (format) { |
+ case gfx::GpuMemoryBuffer::RGBA_8888: |
+ case gfx::GpuMemoryBuffer::BGRA_8888: |
+ return true; |
+ case gfx::GpuMemoryBuffer::RGBX_8888: |
+ return false; |
+ } |
+ |
+ NOTREACHED(); |
+ return false; |
+} |
+ |
+GLenum TextureFormat(gfx::GpuMemoryBuffer::Format format) { |
+ switch (format) { |
+ case gfx::GpuMemoryBuffer::RGBA_8888: |
return GL_RGBA; |
- default: |
+ case gfx::GpuMemoryBuffer::BGRA_8888: |
+ return GL_BGRA_EXT; |
+ case gfx::GpuMemoryBuffer::RGBX_8888: |
NOTREACHED(); |
return 0; |
} |
+ |
+ NOTREACHED(); |
+ return 0; |
} |
-GLenum DataFormat(unsigned internalformat) { |
- return TextureFormat(internalformat); |
+GLenum DataFormat(gfx::GpuMemoryBuffer::Format format) { |
+ return TextureFormat(format); |
} |
-GLenum DataType(unsigned internalformat) { |
- switch (internalformat) { |
- case GL_BGRA8_EXT: |
- case GL_RGBA8_OES: |
+GLenum DataType(gfx::GpuMemoryBuffer::Format format) { |
+ switch (format) { |
+ case gfx::GpuMemoryBuffer::RGBA_8888: |
+ case gfx::GpuMemoryBuffer::BGRA_8888: |
return GL_UNSIGNED_BYTE; |
- default: |
+ case gfx::GpuMemoryBuffer::RGBX_8888: |
NOTREACHED(); |
return 0; |
} |
-} |
-int BytesPerPixel(unsigned internalformat) { |
- switch (internalformat) { |
- case GL_BGRA8_EXT: |
- case GL_RGBA8_OES: |
- return 4; |
- default: |
- NOTREACHED(); |
- return 0; |
- } |
+ NOTREACHED(); |
+ return 0; |
} |
} // namespace |
GLImageMemory::GLImageMemory(const gfx::Size& size, unsigned internalformat) |
- : memory_(NULL), |
- size_(size), |
+ : size_(size), |
internalformat_(internalformat), |
+ memory_(NULL), |
+ format_(gfx::GpuMemoryBuffer::RGBA_8888), |
in_use_(false), |
target_(0), |
need_do_bind_tex_image_(false) |
@@ -91,15 +99,37 @@ GLImageMemory::~GLImageMemory() { |
#endif |
} |
-bool GLImageMemory::Initialize(const unsigned char* memory) { |
- if (!ValidFormat(internalformat_)) { |
- DVLOG(0) << "Invalid format: " << internalformat_; |
+// static |
+size_t GLImageMemory::BytesPerPixel(gfx::GpuMemoryBuffer::Format format) { |
+ switch (format) { |
+ case gfx::GpuMemoryBuffer::RGBA_8888: |
+ case gfx::GpuMemoryBuffer::BGRA_8888: |
+ return 4; |
+ case gfx::GpuMemoryBuffer::RGBX_8888: |
+ NOTREACHED(); |
+ return 0; |
+ } |
+ |
+ NOTREACHED(); |
+ return 0; |
+} |
+ |
+bool GLImageMemory::Initialize(const unsigned char* memory, |
+ gfx::GpuMemoryBuffer::Format format) { |
+ if (!ValidInternalFormat(internalformat_)) { |
+ LOG(ERROR) << "Invalid internalformat: " << internalformat_; |
+ return false; |
+ } |
+ |
+ if (!ValidFormat(format)) { |
+ LOG(ERROR) << "Invalid format: " << format; |
return false; |
} |
DCHECK(memory); |
DCHECK(!memory_); |
memory_ = memory; |
+ format_ = format; |
return true; |
} |
@@ -151,12 +181,12 @@ bool GLImageMemory::CopyTexImage(unsigned target) { |
DCHECK(memory_); |
glTexImage2D(target, |
0, // mip level |
- TextureFormat(internalformat_), |
+ TextureFormat(format_), |
size_.width(), |
size_.height(), |
0, // border |
- DataFormat(internalformat_), |
- DataType(internalformat_), |
+ DataFormat(format_), |
+ DataType(format_), |
memory_); |
return true; |
@@ -186,14 +216,6 @@ bool GLImageMemory::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, |
return false; |
} |
-bool GLImageMemory::HasValidFormat() const { |
- return ValidFormat(internalformat_); |
-} |
- |
-size_t GLImageMemory::Bytes() const { |
- return size_.GetArea() * BytesPerPixel(internalformat_); |
-} |
- |
void GLImageMemory::DoBindTexImage(unsigned target) { |
TRACE_EVENT0("gpu", "GLImageMemory::DoBindTexImage"); |
@@ -216,12 +238,12 @@ void GLImageMemory::DoBindTexImage(unsigned target) { |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
glTexImage2D(GL_TEXTURE_2D, |
0, // mip level |
- TextureFormat(internalformat_), |
+ TextureFormat(format_), |
size_.width(), |
size_.height(), |
0, // border |
- DataFormat(internalformat_), |
- DataType(internalformat_), |
+ DataFormat(format_), |
+ DataType(format_), |
memory_); |
} |
@@ -245,8 +267,8 @@ void GLImageMemory::DoBindTexImage(unsigned target) { |
0, // y-offset |
size_.width(), |
size_.height(), |
- DataFormat(internalformat_), |
- DataType(internalformat_), |
+ DataFormat(format_), |
+ DataType(format_), |
memory_); |
} |
@@ -259,12 +281,12 @@ void GLImageMemory::DoBindTexImage(unsigned target) { |
DCHECK_NE(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), target); |
glTexImage2D(target, |
0, // mip level |
- TextureFormat(internalformat_), |
+ TextureFormat(format_), |
size_.width(), |
size_.height(), |
0, // border |
- DataFormat(internalformat_), |
- DataType(internalformat_), |
+ DataFormat(format_), |
+ DataType(format_), |
memory_); |
} |