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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 return false; | 239 return false; |
240 | 240 |
241 if (target != GL_TEXTURE_RECTANGLE_ARB) { | 241 if (target != GL_TEXTURE_RECTANGLE_ARB) { |
242 // This might be supported in the future. For now, perform strict | 242 // This might be supported in the future. For now, perform strict |
243 // validation so we know what's going on. | 243 // validation so we know what's going on. |
244 LOG(ERROR) << "IOSurface requires TEXTURE_RECTANGLE_ARB target"; | 244 LOG(ERROR) << "IOSurface requires TEXTURE_RECTANGLE_ARB target"; |
245 return false; | 245 return false; |
246 } | 246 } |
247 | 247 |
248 CGLContextObj cgl_context = | 248 CGLContextObj cgl_context = |
249 static_cast<CGLContextObj>(gl::GLContext::GetCurrent()->GetHandle()); | 249 static_cast<CGLContextObj>(GLContext::GetCurrent()->GetHandle()); |
250 | 250 |
251 DCHECK(io_surface_); | 251 DCHECK(io_surface_); |
252 CGLError cgl_error = | 252 CGLError cgl_error = |
253 CGLTexImageIOSurface2D(cgl_context, target, TextureFormat(format_), | 253 CGLTexImageIOSurface2D(cgl_context, target, TextureFormat(format_), |
254 size_.width(), size_.height(), DataFormat(format_), | 254 size_.width(), size_.height(), DataFormat(format_), |
255 DataType(format_), io_surface_.get(), 0); | 255 DataType(format_), io_surface_.get(), 0); |
256 if (cgl_error != kCGLNoError) { | 256 if (cgl_error != kCGLNoError) { |
257 LOG(ERROR) << "Error in CGLTexImageIOSurface2D: " | 257 LOG(ERROR) << "Error in CGLTexImageIOSurface2D: " |
258 << CGLErrorString(cgl_error); | 258 << CGLErrorString(cgl_error); |
259 return false; | 259 return false; |
260 } | 260 } |
261 | 261 |
262 return true; | 262 return true; |
263 } | 263 } |
264 | 264 |
265 bool GLImageIOSurface::CopyTexImage(unsigned target) { | 265 bool GLImageIOSurface::CopyTexImage(unsigned target) { |
266 DCHECK(thread_checker_.CalledOnValidThread()); | 266 DCHECK(thread_checker_.CalledOnValidThread()); |
267 | 267 |
268 if (format_ != gfx::BufferFormat::YUV_420_BIPLANAR) | 268 if (format_ != gfx::BufferFormat::YUV_420_BIPLANAR) |
269 return false; | 269 return false; |
270 | 270 |
271 if (target != GL_TEXTURE_RECTANGLE_ARB) { | 271 if (target != GL_TEXTURE_RECTANGLE_ARB) { |
272 LOG(ERROR) << "YUV_420_BIPLANAR requires GL_TEXTURE_RECTANGLE_ARB target"; | 272 LOG(ERROR) << "YUV_420_BIPLANAR requires GL_TEXTURE_RECTANGLE_ARB target"; |
273 return false; | 273 return false; |
274 } | 274 } |
275 | 275 |
276 gl::GLContext* gl_context = gl::GLContext::GetCurrent(); | 276 GLContext* gl_context = GLContext::GetCurrent(); |
277 DCHECK(gl_context); | 277 DCHECK(gl_context); |
278 | 278 |
279 gl::YUVToRGBConverter* yuv_to_rgb_converter = | 279 YUVToRGBConverter* yuv_to_rgb_converter = gl_context->GetYUVToRGBConverter(); |
280 gl_context->GetYUVToRGBConverter(); | |
281 DCHECK(yuv_to_rgb_converter); | 280 DCHECK(yuv_to_rgb_converter); |
282 | 281 |
283 gl::ScopedSetGLToRealGLApi scoped_set_gl_api; | 282 ScopedSetGLToRealGLApi scoped_set_gl_api; |
284 | 283 |
285 // Note that state restoration is done explicitly instead of scoped binders to | 284 // Note that state restoration is done explicitly instead of scoped binders to |
286 // avoid https://crbug.com/601729. | 285 // avoid https://crbug.com/601729. |
287 GLint rgb_texture = 0; | 286 GLint rgb_texture = 0; |
288 glGetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB, &rgb_texture); | 287 glGetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB, &rgb_texture); |
289 base::ScopedClosureRunner destroy_resources_runner(base::BindBlock(^{ | 288 base::ScopedClosureRunner destroy_resources_runner(base::BindBlock(^{ |
290 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, rgb_texture); | 289 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, rgb_texture); |
291 })); | 290 })); |
292 | 291 |
293 CGLContextObj cgl_context = CGLGetCurrentContext(); | 292 CGLContextObj cgl_context = CGLGetCurrentContext(); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 return cv_pixel_buffer_; | 366 return cv_pixel_buffer_; |
368 } | 367 } |
369 | 368 |
370 // static | 369 // static |
371 unsigned GLImageIOSurface::GetInternalFormatForTesting( | 370 unsigned GLImageIOSurface::GetInternalFormatForTesting( |
372 gfx::BufferFormat format) { | 371 gfx::BufferFormat format) { |
373 DCHECK(ValidFormat(format)); | 372 DCHECK(ValidFormat(format)); |
374 return TextureFormat(format); | 373 return TextureFormat(format); |
375 } | 374 } |
376 } // namespace gl | 375 } // namespace gl |
OLD | NEW |