| 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/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 : size_(size), | 194 : size_(size), |
| 195 internalformat_(internalformat), | 195 internalformat_(internalformat), |
| 196 format_(BufferFormat::RGBA_8888) {} | 196 format_(BufferFormat::RGBA_8888) {} |
| 197 | 197 |
| 198 GLImageIOSurface::~GLImageIOSurface() { | 198 GLImageIOSurface::~GLImageIOSurface() { |
| 199 DCHECK(thread_checker_.CalledOnValidThread()); | 199 DCHECK(thread_checker_.CalledOnValidThread()); |
| 200 DCHECK(!io_surface_); | 200 DCHECK(!io_surface_); |
| 201 } | 201 } |
| 202 | 202 |
| 203 bool GLImageIOSurface::Initialize(IOSurfaceRef io_surface, | 203 bool GLImageIOSurface::Initialize(IOSurfaceRef io_surface, |
| 204 CVPixelBufferRef cv_pixel_buffer, |
| 204 gfx::GenericSharedMemoryId io_surface_id, | 205 gfx::GenericSharedMemoryId io_surface_id, |
| 205 BufferFormat format) { | 206 BufferFormat format) { |
| 206 DCHECK(thread_checker_.CalledOnValidThread()); | 207 DCHECK(thread_checker_.CalledOnValidThread()); |
| 207 DCHECK(!io_surface_); | 208 DCHECK(!io_surface_); |
| 208 | 209 |
| 209 if (!ValidInternalFormat(internalformat_)) { | 210 if (!ValidInternalFormat(internalformat_)) { |
| 210 LOG(ERROR) << "Invalid internalformat: " << internalformat_; | 211 LOG(ERROR) << "Invalid internalformat: " << internalformat_; |
| 211 return false; | 212 return false; |
| 212 } | 213 } |
| 213 | 214 |
| 214 if (!ValidFormat(format)) { | 215 if (!ValidFormat(format)) { |
| 215 LOG(ERROR) << "Invalid format: " << static_cast<int>(format); | 216 LOG(ERROR) << "Invalid format: " << static_cast<int>(format); |
| 216 return false; | 217 return false; |
| 217 } | 218 } |
| 218 | 219 |
| 219 format_ = format; | 220 format_ = format; |
| 220 io_surface_.reset(io_surface, base::scoped_policy::RETAIN); | 221 io_surface_.reset(io_surface, base::scoped_policy::RETAIN); |
| 221 io_surface_id_ = io_surface_id; | 222 io_surface_id_ = io_surface_id; |
| 223 cv_pixel_buffer_.reset(cv_pixel_buffer, base::scoped_policy::RETAIN); |
| 222 return true; | 224 return true; |
| 223 } | 225 } |
| 224 | 226 |
| 225 void GLImageIOSurface::Destroy(bool have_context) { | 227 void GLImageIOSurface::Destroy(bool have_context) { |
| 226 DCHECK(thread_checker_.CalledOnValidThread()); | 228 DCHECK(thread_checker_.CalledOnValidThread()); |
| 227 if (have_context && framebuffer_) { | 229 if (have_context && framebuffer_) { |
| 228 glDeleteProgram(program_); | 230 glDeleteProgram(program_); |
| 229 glDeleteShader(vertex_shader_); | 231 glDeleteShader(vertex_shader_); |
| 230 glDeleteShader(fragment_shader_); | 232 glDeleteShader(fragment_shader_); |
| 231 glDeleteBuffersARB(1, &vertex_buffer_); | 233 glDeleteBuffersARB(1, &vertex_buffer_); |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 g_widget_to_layer_map.Pointer()->erase(widget); | 420 g_widget_to_layer_map.Pointer()->erase(widget); |
| 419 } | 421 } |
| 420 | 422 |
| 421 // static | 423 // static |
| 422 unsigned GLImageIOSurface::GetInternalFormatForTesting( | 424 unsigned GLImageIOSurface::GetInternalFormatForTesting( |
| 423 gfx::BufferFormat format) { | 425 gfx::BufferFormat format) { |
| 424 DCHECK(ValidFormat(format)); | 426 DCHECK(ValidFormat(format)); |
| 425 return TextureFormat(format); | 427 return TextureFormat(format); |
| 426 } | 428 } |
| 427 } // namespace gl | 429 } // namespace gl |
| OLD | NEW |