OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/gl/gl_image_io_surface.h" |
| 6 |
| 7 #include "ui/gl/gl_bindings.h" |
| 8 #include "ui/gl/gl_context.h" |
| 9 #include "ui/gl/io_surface_support_mac.h" |
| 10 |
| 11 namespace gfx { |
| 12 |
| 13 GLImageIOSurface::GLImageIOSurface(gfx::Size size) |
| 14 : io_surface_support_(IOSurfaceSupport::Initialize()), |
| 15 size_(size) { |
| 16 CHECK(io_surface_support_); |
| 17 } |
| 18 |
| 19 GLImageIOSurface::~GLImageIOSurface() { |
| 20 Destroy(); |
| 21 } |
| 22 |
| 23 bool GLImageIOSurface::Initialize(gfx::GpuMemoryBufferHandle buffer) { |
| 24 io_surface_.reset(io_surface_support_->IOSurfaceLookup(buffer.io_surface_id)); |
| 25 if (!io_surface_) { |
| 26 LOG(ERROR) << "IOSurface lookup failed"; |
| 27 return false; |
| 28 } |
| 29 |
| 30 return true; |
| 31 } |
| 32 |
| 33 void GLImageIOSurface::Destroy() { |
| 34 } |
| 35 |
| 36 gfx::Size GLImageIOSurface::GetSize() { |
| 37 return size_; |
| 38 } |
| 39 |
| 40 bool GLImageIOSurface::BindTexImage(unsigned target) { |
| 41 if (target != GL_TEXTURE_RECTANGLE_ARB) { |
| 42 // This might be supported in the future. For now, perform strict |
| 43 // validation so we know what's going on. |
| 44 LOG(ERROR) << "IOSurface requires TEXTURE_RECTANGLE_ARB target"; |
| 45 return false; |
| 46 } |
| 47 |
| 48 CGLContextObj cgl_context = static_cast<CGLContextObj>( |
| 49 GLContext::GetCurrent()->GetHandle()); |
| 50 |
| 51 DCHECK(io_surface_); |
| 52 CGLError cgl_error = io_surface_support_->CGLTexImageIOSurface2D( |
| 53 cgl_context, |
| 54 target, |
| 55 GL_RGBA, |
| 56 size_.width(), |
| 57 size_.height(), |
| 58 GL_BGRA, |
| 59 GL_UNSIGNED_INT_8_8_8_8_REV, |
| 60 io_surface_.get(), |
| 61 0); |
| 62 if (cgl_error != kCGLNoError) { |
| 63 LOG(ERROR) << "Error in CGLTexImageIOSurface2D"; |
| 64 return false; |
| 65 } |
| 66 |
| 67 return true; |
| 68 } |
| 69 |
| 70 void GLImageIOSurface::ReleaseTexImage(unsigned target) { |
| 71 } |
| 72 |
| 73 void GLImageIOSurface::WillUseTexImage() { |
| 74 } |
| 75 |
| 76 void GLImageIOSurface::DidUseTexImage() { |
| 77 } |
| 78 |
| 79 } // namespace gfx |
OLD | NEW |