Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(572)

Unified Diff: ui/gl/gl_image_ozone_native_pixmap.cc

Issue 2037983003: gl: Check format is valid given an internal format. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make validation as restrictive as possible. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gl/gl_image_ozone_native_pixmap.h ('k') | ui/gl/gl_image_ozone_native_pixmap_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gl/gl_image_ozone_native_pixmap.cc
diff --git a/ui/gl/gl_image_ozone_native_pixmap.cc b/ui/gl/gl_image_ozone_native_pixmap.cc
index ed721b9b265a9c304b3493789442f81e279132db..a97025902ce017bb70ff13b7a850aa6bb770aae3 100644
--- a/ui/gl/gl_image_ozone_native_pixmap.cc
+++ b/ui/gl/gl_image_ozone_native_pixmap.cc
@@ -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
« no previous file with comments | « ui/gl/gl_image_ozone_native_pixmap.h ('k') | ui/gl/gl_image_ozone_native_pixmap_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698