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"
10 // Note that this must be included after gl_bindings.h to avoid conflicts.
11 #include <OpenGL/CGLIOSurface.h>
15 GLImageIOSurface::GLImageIOSurface(const gfx::Size
& size
) : size_(size
) {
18 GLImageIOSurface::~GLImageIOSurface() {
22 bool GLImageIOSurface::Initialize(const gfx::GpuMemoryBufferHandle
& handle
) {
23 io_surface_
.reset(IOSurfaceLookup(handle
.io_surface_id
));
25 LOG(ERROR
) << "IOSurface lookup failed";
32 void GLImageIOSurface::Destroy(bool have_context
) {
36 gfx::Size
GLImageIOSurface::GetSize() { return size_
; }
38 bool GLImageIOSurface::BindTexImage(unsigned target
) {
39 if (target
!= GL_TEXTURE_RECTANGLE_ARB
) {
40 // This might be supported in the future. For now, perform strict
41 // validation so we know what's going on.
42 LOG(ERROR
) << "IOSurface requires TEXTURE_RECTANGLE_ARB target";
46 CGLContextObj cgl_context
=
47 static_cast<CGLContextObj
>(GLContext::GetCurrent()->GetHandle());
50 CGLError cgl_error
= CGLTexImageIOSurface2D(cgl_context
,
56 GL_UNSIGNED_INT_8_8_8_8_REV
,
59 if (cgl_error
!= kCGLNoError
) {
60 LOG(ERROR
) << "Error in CGLTexImageIOSurface2D";
67 bool GLImageIOSurface::CopyTexImage(unsigned target
) {
71 bool GLImageIOSurface::ScheduleOverlayPlane(gfx::AcceleratedWidget widget
,
73 OverlayTransform transform
,
74 const Rect
& bounds_rect
,
75 const RectF
& crop_rect
) {