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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/buffer_format_util.h" 5 #include "ui/gfx/buffer_format_util.h"
6 #include "ui/gl/gl_image_ozone_native_pixmap.h" 6 #include "ui/gl/gl_image_ozone_native_pixmap.h"
7 7
8 #define FOURCC(a, b, c, d) \ 8 #define FOURCC(a, b, c, d) \
9 ((static_cast<uint32_t>(a)) | (static_cast<uint32_t>(b) << 8) | \ 9 ((static_cast<uint32_t>(a)) | (static_cast<uint32_t>(b) << 8) | \
10 (static_cast<uint32_t>(c) << 16) | (static_cast<uint32_t>(d) << 24)) 10 (static_cast<uint32_t>(c) << 16) | (static_cast<uint32_t>(d) << 24))
11 11
12 #define DRM_FORMAT_R8 FOURCC('R', '8', ' ', ' ') 12 #define DRM_FORMAT_R8 FOURCC('R', '8', ' ', ' ')
13 #define DRM_FORMAT_RGB565 FOURCC('R', 'G', '1', '6') 13 #define DRM_FORMAT_RGB565 FOURCC('R', 'G', '1', '6')
14 #define DRM_FORMAT_ARGB8888 FOURCC('A', 'R', '2', '4') 14 #define DRM_FORMAT_ARGB8888 FOURCC('A', 'R', '2', '4')
15 #define DRM_FORMAT_ABGR8888 FOURCC('A', 'B', '2', '4') 15 #define DRM_FORMAT_ABGR8888 FOURCC('A', 'B', '2', '4')
16 #define DRM_FORMAT_XRGB8888 FOURCC('X', 'R', '2', '4') 16 #define DRM_FORMAT_XRGB8888 FOURCC('X', 'R', '2', '4')
17 #define DRM_FORMAT_XBGR8888 FOURCC('X', 'B', '2', '4') 17 #define DRM_FORMAT_XBGR8888 FOURCC('X', 'B', '2', '4')
18 18
19 namespace gl { 19 namespace gl {
20 namespace { 20 namespace {
21 21
22 bool ValidInternalFormat(unsigned internalformat) { 22 bool ValidInternalFormat(unsigned internalformat, gfx::BufferFormat format) {
23 switch (internalformat) { 23 switch (internalformat) {
24 case GL_RGB: 24 case GL_RGB:
25 return format == gfx::BufferFormat::BGR_565 ||
26 format == gfx::BufferFormat::RGBX_8888 ||
27 format == gfx::BufferFormat::BGRX_8888;
25 case GL_RGBA: 28 case GL_RGBA:
29 return format == gfx::BufferFormat::RGBA_8888;
26 case GL_BGRA_EXT: 30 case GL_BGRA_EXT:
31 return format == gfx::BufferFormat::BGRA_8888;
27 case GL_RED_EXT: 32 case GL_RED_EXT:
28 return true; 33 return format == gfx::BufferFormat::R_8;
29 default: 34 default:
30 return false; 35 return false;
31 } 36 }
32 } 37 }
33 38
34 bool ValidFormat(gfx::BufferFormat format) { 39 bool ValidFormat(gfx::BufferFormat format) {
35 switch (format) { 40 switch (format) {
36 case gfx::BufferFormat::R_8: 41 case gfx::BufferFormat::R_8:
37 case gfx::BufferFormat::BGR_565: 42 case gfx::BufferFormat::BGR_565:
38 case gfx::BufferFormat::RGBA_8888: 43 case gfx::BufferFormat::RGBA_8888:
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 bool GLImageOzoneNativePixmap::Initialize(ui::NativePixmap* pixmap, 104 bool GLImageOzoneNativePixmap::Initialize(ui::NativePixmap* pixmap,
100 gfx::BufferFormat format) { 105 gfx::BufferFormat format) {
101 DCHECK(!pixmap_); 106 DCHECK(!pixmap_);
102 if (pixmap->GetEGLClientBuffer()) { 107 if (pixmap->GetEGLClientBuffer()) {
103 EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE}; 108 EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE};
104 if (!GLImageEGL::Initialize(EGL_NATIVE_PIXMAP_KHR, 109 if (!GLImageEGL::Initialize(EGL_NATIVE_PIXMAP_KHR,
105 pixmap->GetEGLClientBuffer(), attrs)) { 110 pixmap->GetEGLClientBuffer(), attrs)) {
106 return false; 111 return false;
107 } 112 }
108 } else if (pixmap->AreDmaBufFdsValid()) { 113 } else if (pixmap->AreDmaBufFdsValid()) {
109 if (!ValidInternalFormat(internalformat_)) {
110 LOG(ERROR) << "Invalid internalformat: " << internalformat_;
111 return false;
112 }
113 114
114 if (!ValidFormat(format)) { 115 if (!ValidFormat(format)) {
115 LOG(ERROR) << "Invalid format: " << static_cast<int>(format); 116 LOG(ERROR) << "Invalid format: " << static_cast<int>(format);
116 return false; 117 return false;
117 } 118 }
118 119
120 if (!ValidInternalFormat(internalformat_, format)) {
121 LOG(ERROR) << "Invalid internalformat: " << internalformat_
122 << " for format: " << static_cast<int>(format);
123 return false;
124 }
125
119 // Note: If eglCreateImageKHR is successful for a EGL_LINUX_DMA_BUF_EXT 126 // Note: If eglCreateImageKHR is successful for a EGL_LINUX_DMA_BUF_EXT
120 // target, the EGL will take a reference to the dma_buf. 127 // target, the EGL will take a reference to the dma_buf.
121 std::vector<EGLint> attrs; 128 std::vector<EGLint> attrs;
122 attrs.push_back(EGL_WIDTH); 129 attrs.push_back(EGL_WIDTH);
123 attrs.push_back(size_.width()); 130 attrs.push_back(size_.width());
124 attrs.push_back(EGL_HEIGHT); 131 attrs.push_back(EGL_HEIGHT);
125 attrs.push_back(size_.height()); 132 attrs.push_back(size_.height());
126 attrs.push_back(EGL_LINUX_DRM_FOURCC_EXT); 133 attrs.push_back(EGL_LINUX_DRM_FOURCC_EXT);
127 attrs.push_back(FourCC(format)); 134 attrs.push_back(FourCC(format));
128 135
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 crop_rect); 188 crop_rect);
182 } 189 }
183 190
184 void GLImageOzoneNativePixmap::OnMemoryDump( 191 void GLImageOzoneNativePixmap::OnMemoryDump(
185 base::trace_event::ProcessMemoryDump* pmd, 192 base::trace_event::ProcessMemoryDump* pmd,
186 uint64_t process_tracing_id, 193 uint64_t process_tracing_id,
187 const std::string& dump_name) { 194 const std::string& dump_name) {
188 // TODO(ericrk): Implement GLImage OnMemoryDump. crbug.com/514914 195 // TODO(ericrk): Implement GLImage OnMemoryDump. crbug.com/514914
189 } 196 }
190 197
198 // static
199 unsigned GLImageOzoneNativePixmap::GetInternalFormatForTesting(
200 gfx::BufferFormat format) {
201 DCHECK(ValidFormat(format));
202 switch (format) {
203 case gfx::BufferFormat::R_8:
204 return GL_RED_EXT;
205 case gfx::BufferFormat::BGR_565:
206 case gfx::BufferFormat::RGBA_8888:
207 case gfx::BufferFormat::RGBX_8888:
208 case gfx::BufferFormat::BGRA_8888:
209 case gfx::BufferFormat::BGRX_8888:
210 return GL_RGBA;
211 case gfx::BufferFormat::ATC:
212 case gfx::BufferFormat::ATCIA:
213 case gfx::BufferFormat::DXT1:
214 case gfx::BufferFormat::DXT5:
215 case gfx::BufferFormat::ETC1:
216 case gfx::BufferFormat::RGBA_4444:
217 case gfx::BufferFormat::YUV_420:
218 case gfx::BufferFormat::YUV_420_BIPLANAR:
219 case gfx::BufferFormat::UYVY_422:
220 NOTREACHED();
221 return GL_NONE;
222 }
223
224 NOTREACHED();
225 return GL_NONE;
226 }
227
191 } // namespace gl 228 } // namespace gl
OLDNEW
« 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