OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/gl/gl_image_io_surface.h" | 5 #include "ui/gl/gl_image_io_surface.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/mac/bind_objc_block.h" | 10 #include "base/mac/bind_objc_block.h" |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 case gfx::BufferFormat::YUV_420_BIPLANAR: | 161 case gfx::BufferFormat::YUV_420_BIPLANAR: |
162 NOTREACHED(); | 162 NOTREACHED(); |
163 return 0; | 163 return 0; |
164 } | 164 } |
165 | 165 |
166 NOTREACHED(); | 166 NOTREACHED(); |
167 return 0; | 167 return 0; |
168 } | 168 } |
169 | 169 |
170 // When an IOSurface is bound to a texture with internalformat "GL_RGB", many | 170 // When an IOSurface is bound to a texture with internalformat "GL_RGB", many |
171 // OpenGL operations are broken. Therefore, don't allow an IOSurface to be bound | 171 // OpenGL operations are broken. Therefore, never allow an IOSurface to be bound |
172 // with GL_RGB unless overridden via BindTexImageWithInternalformat. | 172 // with GL_RGB. https://crbug.com/595948. |
173 // crbug.com/595948, crbug.com/699566. | |
174 GLenum ConvertRequestedInternalFormat(GLenum internalformat) { | 173 GLenum ConvertRequestedInternalFormat(GLenum internalformat) { |
175 if (internalformat == GL_RGB) | 174 if (internalformat == GL_RGB) |
176 return GL_RGBA; | 175 return GL_RGBA; |
177 return internalformat; | 176 return internalformat; |
178 } | 177 } |
179 | 178 |
180 } // namespace | 179 } // namespace |
181 | 180 |
182 GLImageIOSurface::GLImageIOSurface(const gfx::Size& size, | 181 GLImageIOSurface::GLImageIOSurface(const gfx::Size& size, |
183 unsigned internalformat) | 182 unsigned internalformat) |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 | 230 |
232 gfx::Size GLImageIOSurface::GetSize() { | 231 gfx::Size GLImageIOSurface::GetSize() { |
233 return size_; | 232 return size_; |
234 } | 233 } |
235 | 234 |
236 unsigned GLImageIOSurface::GetInternalFormat() { | 235 unsigned GLImageIOSurface::GetInternalFormat() { |
237 return internalformat_; | 236 return internalformat_; |
238 } | 237 } |
239 | 238 |
240 bool GLImageIOSurface::BindTexImage(unsigned target) { | 239 bool GLImageIOSurface::BindTexImage(unsigned target) { |
241 return BindTexImageWithInternalformat(target, 0); | |
242 } | |
243 | |
244 bool GLImageIOSurface::BindTexImageWithInternalformat(unsigned target, | |
245 unsigned internalformat) { | |
246 DCHECK(thread_checker_.CalledOnValidThread()); | 240 DCHECK(thread_checker_.CalledOnValidThread()); |
247 TRACE_EVENT0("gpu", "GLImageIOSurface::BindTexImage"); | 241 TRACE_EVENT0("gpu", "GLImageIOSurface::BindTexImage"); |
248 base::TimeTicks start_time = base::TimeTicks::Now(); | 242 base::TimeTicks start_time = base::TimeTicks::Now(); |
249 | 243 |
250 // YUV_420_BIPLANAR is not supported by BindTexImage. | 244 // YUV_420_BIPLANAR is not supported by BindTexImage. |
251 // CopyTexImage is supported by this format as that performs conversion to RGB | 245 // CopyTexImage is supported by this format as that performs conversion to RGB |
252 // as part of the copy operation. | 246 // as part of the copy operation. |
253 if (format_ == gfx::BufferFormat::YUV_420_BIPLANAR) | 247 if (format_ == gfx::BufferFormat::YUV_420_BIPLANAR) |
254 return false; | 248 return false; |
255 | 249 |
256 if (target != GL_TEXTURE_RECTANGLE_ARB) { | 250 if (target != GL_TEXTURE_RECTANGLE_ARB) { |
257 // This might be supported in the future. For now, perform strict | 251 // This might be supported in the future. For now, perform strict |
258 // validation so we know what's going on. | 252 // validation so we know what's going on. |
259 LOG(ERROR) << "IOSurface requires TEXTURE_RECTANGLE_ARB target"; | 253 LOG(ERROR) << "IOSurface requires TEXTURE_RECTANGLE_ARB target"; |
260 return false; | 254 return false; |
261 } | 255 } |
262 | 256 |
263 CGLContextObj cgl_context = | 257 CGLContextObj cgl_context = |
264 static_cast<CGLContextObj>(GLContext::GetCurrent()->GetHandle()); | 258 static_cast<CGLContextObj>(GLContext::GetCurrent()->GetHandle()); |
265 | 259 |
266 DCHECK(io_surface_); | 260 DCHECK(io_surface_); |
267 | 261 CGLError cgl_error = |
268 GLenum texture_format = | 262 CGLTexImageIOSurface2D(cgl_context, target, TextureFormat(format_), |
269 internalformat ? internalformat : TextureFormat(format_); | 263 size_.width(), size_.height(), DataFormat(format_), |
270 CGLError cgl_error = CGLTexImageIOSurface2D( | 264 DataType(format_), io_surface_.get(), 0); |
271 cgl_context, target, texture_format, size_.width(), size_.height(), | |
272 DataFormat(format_), DataType(format_), io_surface_.get(), 0); | |
273 if (cgl_error != kCGLNoError) { | 265 if (cgl_error != kCGLNoError) { |
274 LOG(ERROR) << "Error in CGLTexImageIOSurface2D: " | 266 LOG(ERROR) << "Error in CGLTexImageIOSurface2D: " |
275 << CGLErrorString(cgl_error); | 267 << CGLErrorString(cgl_error); |
276 return false; | 268 return false; |
277 } | 269 } |
278 | 270 |
279 UMA_HISTOGRAM_TIMES("GPU.IOSurface.TexImageTime", | 271 UMA_HISTOGRAM_TIMES("GPU.IOSurface.TexImageTime", |
280 base::TimeTicks::Now() - start_time); | 272 base::TimeTicks::Now() - start_time); |
281 return true; | 273 return true; |
282 } | 274 } |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 } | 409 } |
418 | 410 |
419 // static | 411 // static |
420 GLImageIOSurface* GLImageIOSurface::FromGLImage(GLImage* image) { | 412 GLImageIOSurface* GLImageIOSurface::FromGLImage(GLImage* image) { |
421 if (!image || image->GetType() != Type::IOSURFACE) | 413 if (!image || image->GetType() != Type::IOSURFACE) |
422 return nullptr; | 414 return nullptr; |
423 return static_cast<GLImageIOSurface*>(image); | 415 return static_cast<GLImageIOSurface*>(image); |
424 } | 416 } |
425 | 417 |
426 } // namespace gl | 418 } // namespace gl |
OLD | NEW |