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.
5 #include "ui/gl/gl_image_egl.h"
7 #include "ui/gl/gl_bindings.h"
11 GLImageEGL::GLImageEGL(gfx::Size size
)
12 : egl_image_(EGL_NO_IMAGE_KHR
),
16 GLImageEGL::~GLImageEGL() {
20 bool GLImageEGL::Initialize(gfx::GpuMemoryBufferHandle buffer
) {
21 EGLClientBuffer cbuf
= static_cast<EGLClientBuffer
>(buffer
);
23 EGL_IMAGE_PRESERVED_KHR
, EGL_TRUE
,
26 egl_image_
= eglCreateImageKHR(
27 eglGetDisplay(EGL_DEFAULT_DISPLAY
),
29 EGL_NATIVE_BUFFER_ANDROID
,
33 if (egl_image_
== EGL_NO_IMAGE_KHR
) {
34 EGLint error
= eglGetError();
35 LOG(ERROR
) << "Error creating EGLImage: " << error
;
42 bool GLImageEGL::BindTexImage() {
43 if (egl_image_
== EGL_NO_IMAGE_KHR
) {
44 LOG(ERROR
) << "NULL EGLImage in BindTexImage";
48 glEGLImageTargetTexture2DOES(GL_TEXTURE_2D
, egl_image_
);
50 if (glGetError() != GL_NO_ERROR
) {
57 gfx::Size
GLImageEGL::GetSize() {
61 void GLImageEGL::Destroy() {
62 if (egl_image_
== EGL_NO_IMAGE_KHR
)
65 EGLBoolean success
= eglDestroyImageKHR(
66 eglGetDisplay(EGL_DEFAULT_DISPLAY
), egl_image_
);
68 if (success
== EGL_FALSE
) {
69 EGLint error
= eglGetError();
70 LOG(ERROR
) << "Error destroying EGLImage: " << error
;
73 egl_image_
= EGL_NO_IMAGE_KHR
;
76 void GLImageEGL::ReleaseTexImage() {
77 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 0, 0, 0, GL_RGBA
, GL_UNSIGNED_BYTE
,