Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / ui / gl / gl_image_io_surface.cc
blobe20c739cffad6ce232405e4cc460e7aeec078a39
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
3 // found in the LICENSE file.
5 #include "ui/gl/gl_image_io_surface.h"
7 #include "ui/gl/gl_bindings.h"
8 #include "ui/gl/gl_context.h"
9 #include "ui/gl/io_surface_support_mac.h"
11 namespace gfx {
13 GLImageIOSurface::GLImageIOSurface(gfx::Size size)
14 : io_surface_support_(IOSurfaceSupport::Initialize()), size_(size) {
15 CHECK(io_surface_support_);
18 GLImageIOSurface::~GLImageIOSurface() { Destroy(); }
20 bool GLImageIOSurface::Initialize(gfx::GpuMemoryBufferHandle buffer) {
21 io_surface_.reset(io_surface_support_->IOSurfaceLookup(buffer.io_surface_id));
22 if (!io_surface_) {
23 LOG(ERROR) << "IOSurface lookup failed";
24 return false;
27 return true;
30 gfx::Size GLImageIOSurface::GetSize() { return size_; }
32 bool GLImageIOSurface::BindTexImage(unsigned target) {
33 if (target != GL_TEXTURE_RECTANGLE_ARB) {
34 // This might be supported in the future. For now, perform strict
35 // validation so we know what's going on.
36 LOG(ERROR) << "IOSurface requires TEXTURE_RECTANGLE_ARB target";
37 return false;
40 CGLContextObj cgl_context =
41 static_cast<CGLContextObj>(GLContext::GetCurrent()->GetHandle());
43 DCHECK(io_surface_);
44 CGLError cgl_error =
45 io_surface_support_->CGLTexImageIOSurface2D(cgl_context,
46 target,
47 GL_RGBA,
48 size_.width(),
49 size_.height(),
50 GL_BGRA,
51 GL_UNSIGNED_INT_8_8_8_8_REV,
52 io_surface_.get(),
53 0);
54 if (cgl_error != kCGLNoError) {
55 LOG(ERROR) << "Error in CGLTexImageIOSurface2D";
56 return false;
59 return true;
62 } // namespace gfx