Commit 071378ae authored by dcastagna's avatar dcastagna Committed by Commit bot

gl: Check format is valid given an internal format.

GLImageOzoneNativePixmap used to check that format and internal format
were valid, but didn't check that they were compatible.

This CL restricts the valid internalformats given the buffer format
used to initialize the image (e.g: it's now prohibited to initialize with
an R8 buffer an GL_RGBA image).

TEST='gl_unittests --gtest_also_run_disabled_tests' on samus

Review-Url: https://codereview.chromium.org/2037983003
Cr-Commit-Position: refs/heads/master@{#397876}
parent 13a57bce
......@@ -19,13 +19,18 @@
namespace gl {
namespace {
bool ValidInternalFormat(unsigned internalformat) {
bool ValidInternalFormat(unsigned internalformat, gfx::BufferFormat format) {
switch (internalformat) {
case GL_RGB:
return format == gfx::BufferFormat::BGR_565 ||
format == gfx::BufferFormat::RGBX_8888 ||
format == gfx::BufferFormat::BGRX_8888;
case GL_RGBA:
return format == gfx::BufferFormat::RGBA_8888;
case GL_BGRA_EXT:
return format == gfx::BufferFormat::BGRA_8888;
case GL_RED_EXT:
return true;
return format == gfx::BufferFormat::R_8;
default:
return false;
}
......@@ -106,16 +111,18 @@ bool GLImageOzoneNativePixmap::Initialize(ui::NativePixmap* pixmap,
return false;
}
} else if (pixmap->AreDmaBufFdsValid()) {
if (!ValidInternalFormat(internalformat_)) {
LOG(ERROR) << "Invalid internalformat: " << internalformat_;
return false;
}
if (!ValidFormat(format)) {
LOG(ERROR) << "Invalid format: " << static_cast<int>(format);
return false;
}
if (!ValidInternalFormat(internalformat_, format)) {
LOG(ERROR) << "Invalid internalformat: " << internalformat_
<< " for format: " << static_cast<int>(format);
return false;
}
// Note: If eglCreateImageKHR is successful for a EGL_LINUX_DMA_BUF_EXT
// target, the EGL will take a reference to the dma_buf.
std::vector<EGLint> attrs;
......@@ -188,4 +195,34 @@ void GLImageOzoneNativePixmap::OnMemoryDump(
// TODO(ericrk): Implement GLImage OnMemoryDump. crbug.com/514914
}
// static
unsigned GLImageOzoneNativePixmap::GetInternalFormatForTesting(
gfx::BufferFormat format) {
DCHECK(ValidFormat(format));
switch (format) {
case gfx::BufferFormat::R_8:
return GL_RED_EXT;
case gfx::BufferFormat::BGR_565:
case gfx::BufferFormat::RGBA_8888:
case gfx::BufferFormat::RGBX_8888:
case gfx::BufferFormat::BGRA_8888:
case gfx::BufferFormat::BGRX_8888:
return GL_RGBA;
case gfx::BufferFormat::ATC:
case gfx::BufferFormat::ATCIA:
case gfx::BufferFormat::DXT1:
case gfx::BufferFormat::DXT5:
case gfx::BufferFormat::ETC1:
case gfx::BufferFormat::RGBA_4444:
case gfx::BufferFormat::YUV_420:
case gfx::BufferFormat::YUV_420_BIPLANAR:
case gfx::BufferFormat::UYVY_422:
NOTREACHED();
return GL_NONE;
}
NOTREACHED();
return GL_NONE;
}
} // namespace gl
......@@ -33,6 +33,8 @@ class GL_EXPORT GLImageOzoneNativePixmap : public GLImageEGL {
uint64_t process_tracing_id,
const std::string& dump_name) override;
static unsigned GetInternalFormatForTesting(gfx::BufferFormat format);
protected:
~GLImageOzoneNativePixmap() override;
......
......@@ -44,8 +44,8 @@ class GLImageOzoneNativePixmapTestDelegate {
client_pixmap->Unmap();
}
scoped_refptr<GLImageOzoneNativePixmap> image(
new GLImageOzoneNativePixmap(size, GL_RGBA));
scoped_refptr<GLImageOzoneNativePixmap> image(new GLImageOzoneNativePixmap(
size, GLImageOzoneNativePixmap::GetInternalFormatForTesting(format)));
EXPECT_TRUE(image->Initialize(pixmap.get(), pixmap->GetBufferFormat()));
return image;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment