• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_egl.h"
6 
7 #include "ui/gl/gl_surface_egl.h"
8 
9 namespace gfx {
10 
GLImageEGL(gfx::Size size)11 GLImageEGL::GLImageEGL(gfx::Size size)
12     : egl_image_(EGL_NO_IMAGE_KHR), size_(size) {}
13 
~GLImageEGL()14 GLImageEGL::~GLImageEGL() { Destroy(); }
15 
Initialize(EGLenum target,EGLClientBuffer buffer,const EGLint * attrs)16 bool GLImageEGL::Initialize(EGLenum target,
17                             EGLClientBuffer buffer,
18                             const EGLint* attrs) {
19   DCHECK_EQ(EGL_NO_IMAGE_KHR, egl_image_);
20   egl_image_ = eglCreateImageKHR(GLSurfaceEGL::GetHardwareDisplay(),
21                                  EGL_NO_CONTEXT,
22                                  target,
23                                  buffer,
24                                  attrs);
25   if (egl_image_ == EGL_NO_IMAGE_KHR) {
26     EGLint error = eglGetError();
27     LOG(ERROR) << "Error creating EGLImage: " << error;
28     return false;
29   }
30 
31   return true;
32 }
33 
Destroy()34 void GLImageEGL::Destroy() {
35   if (egl_image_ != EGL_NO_IMAGE_KHR) {
36     eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), egl_image_);
37     egl_image_ = EGL_NO_IMAGE_KHR;
38   }
39 }
40 
GetSize()41 gfx::Size GLImageEGL::GetSize() { return size_; }
42 
BindTexImage(unsigned target)43 bool GLImageEGL::BindTexImage(unsigned target) {
44   DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_);
45   glEGLImageTargetTexture2DOES(target, egl_image_);
46   DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
47   return true;
48 }
49 
50 }  // namespace gfx
51