| 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 "ui/gl/gl_bindings.h" | 7 #include "ui/gl/gl_bindings.h" |
| 8 #include "ui/gl/gl_context.h" | 8 #include "ui/gl/gl_context.h" |
| 9 #include "ui/gl/io_surface_support_mac.h" | 9 |
| 10 // Note that this must be included after gl_bindings.h to avoid conflicts. |
| 11 #include <OpenGL/CGLIOSurface.h> |
| 10 | 12 |
| 11 namespace gfx { | 13 namespace gfx { |
| 12 | 14 |
| 13 GLImageIOSurface::GLImageIOSurface(gfx::Size size) | 15 GLImageIOSurface::GLImageIOSurface(gfx::Size size) |
| 14 : io_surface_support_(IOSurfaceSupport::Initialize()), size_(size) { | 16 : size_(size) {} |
| 15 CHECK(io_surface_support_); | |
| 16 } | |
| 17 | 17 |
| 18 GLImageIOSurface::~GLImageIOSurface() { Destroy(); } | 18 GLImageIOSurface::~GLImageIOSurface() { Destroy(); } |
| 19 | 19 |
| 20 bool GLImageIOSurface::Initialize(gfx::GpuMemoryBufferHandle buffer) { | 20 bool GLImageIOSurface::Initialize(gfx::GpuMemoryBufferHandle buffer) { |
| 21 io_surface_.reset(io_surface_support_->IOSurfaceLookup(buffer.io_surface_id)); | 21 io_surface_.reset(IOSurfaceLookup(buffer.io_surface_id)); |
| 22 if (!io_surface_) { | 22 if (!io_surface_) { |
| 23 LOG(ERROR) << "IOSurface lookup failed"; | 23 LOG(ERROR) << "IOSurface lookup failed"; |
| 24 return false; | 24 return false; |
| 25 } | 25 } |
| 26 | 26 |
| 27 return true; | 27 return true; |
| 28 } | 28 } |
| 29 | 29 |
| 30 gfx::Size GLImageIOSurface::GetSize() { return size_; } | 30 gfx::Size GLImageIOSurface::GetSize() { return size_; } |
| 31 | 31 |
| 32 bool GLImageIOSurface::BindTexImage(unsigned target) { | 32 bool GLImageIOSurface::BindTexImage(unsigned target) { |
| 33 if (target != GL_TEXTURE_RECTANGLE_ARB) { | 33 if (target != GL_TEXTURE_RECTANGLE_ARB) { |
| 34 // This might be supported in the future. For now, perform strict | 34 // This might be supported in the future. For now, perform strict |
| 35 // validation so we know what's going on. | 35 // validation so we know what's going on. |
| 36 LOG(ERROR) << "IOSurface requires TEXTURE_RECTANGLE_ARB target"; | 36 LOG(ERROR) << "IOSurface requires TEXTURE_RECTANGLE_ARB target"; |
| 37 return false; | 37 return false; |
| 38 } | 38 } |
| 39 | 39 |
| 40 CGLContextObj cgl_context = | 40 CGLContextObj cgl_context = |
| 41 static_cast<CGLContextObj>(GLContext::GetCurrent()->GetHandle()); | 41 static_cast<CGLContextObj>(GLContext::GetCurrent()->GetHandle()); |
| 42 | 42 |
| 43 DCHECK(io_surface_); | 43 DCHECK(io_surface_); |
| 44 CGLError cgl_error = | 44 CGLError cgl_error = CGLTexImageIOSurface2D(cgl_context, |
| 45 io_surface_support_->CGLTexImageIOSurface2D(cgl_context, | 45 target, |
| 46 target, | 46 GL_RGBA, |
| 47 GL_RGBA, | 47 size_.width(), |
| 48 size_.width(), | 48 size_.height(), |
| 49 size_.height(), | 49 GL_BGRA, |
| 50 GL_BGRA, | 50 GL_UNSIGNED_INT_8_8_8_8_REV, |
| 51 GL_UNSIGNED_INT_8_8_8_8_REV, | 51 io_surface_.get(), |
| 52 io_surface_.get(), | 52 0); |
| 53 0); | |
| 54 if (cgl_error != kCGLNoError) { | 53 if (cgl_error != kCGLNoError) { |
| 55 LOG(ERROR) << "Error in CGLTexImageIOSurface2D"; | 54 LOG(ERROR) << "Error in CGLTexImageIOSurface2D"; |
| 56 return false; | 55 return false; |
| 57 } | 56 } |
| 58 | 57 |
| 59 return true; | 58 return true; |
| 60 } | 59 } |
| 61 | 60 |
| 62 } // namespace gfx | 61 } // namespace gfx |
| OLD | NEW |