Index: ui/gl/gl_image_egl.cc |
diff --git a/ui/gl/gl_image_egl.cc b/ui/gl/gl_image_egl.cc |
index ddd2f6f5e29552cba3706e78fadae7d5951bbfb3..6f65727b7285e3951763750b117b3b8d08481c5d 100644 |
--- a/ui/gl/gl_image_egl.cc |
+++ b/ui/gl/gl_image_egl.cc |
@@ -6,6 +6,7 @@ |
#include "ui/gl/gl_bindings.h" |
#include "ui/gl/gl_surface_egl.h" |
+#include "ui/gl/scoped_binders.h" |
namespace gfx { |
@@ -14,8 +15,9 @@ GLImageEGL::GLImageEGL(gfx::Size size) |
size_(size), |
release_after_use_(false), |
in_use_(false), |
- target_(0) { |
-} |
+ target_(0), |
+ egl_image_for_unbind_(EGL_NO_IMAGE_KHR), |
+ texture_id_(0) {} |
GLImageEGL::~GLImageEGL() { |
Destroy(); |
@@ -27,12 +29,11 @@ bool GLImageEGL::Initialize(gfx::GpuMemoryBufferHandle buffer) { |
EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, |
EGL_NONE, |
}; |
- egl_image_ = eglCreateImageKHR( |
- GLSurfaceEGL::GetHardwareDisplay(), |
- EGL_NO_CONTEXT, |
- EGL_NATIVE_BUFFER_ANDROID, |
- buffer.native_buffer, |
- attrs); |
+ egl_image_ = eglCreateImageKHR(GLSurfaceEGL::GetHardwareDisplay(), |
+ EGL_NO_CONTEXT, |
+ EGL_NATIVE_BUFFER_ANDROID, |
+ buffer.native_buffer, |
+ attrs); |
if (egl_image_ == EGL_NO_IMAGE_KHR) { |
EGLint error = eglGetError(); |
@@ -44,18 +45,28 @@ bool GLImageEGL::Initialize(gfx::GpuMemoryBufferHandle buffer) { |
} |
void GLImageEGL::Destroy() { |
- if (egl_image_ == EGL_NO_IMAGE_KHR) |
+ if (egl_image_ == EGL_NO_IMAGE_KHR || |
+ egl_image_for_unbind_ == EGL_NO_IMAGE_KHR) |
reveman
2014/03/20 13:02:05
This is not right. You will call eglDestroyImageKH
|
return; |
EGLBoolean success = eglDestroyImageKHR( |
GLSurfaceEGL::GetHardwareDisplay(), egl_image_); |
- if (success == EGL_FALSE) { |
+ EGLBoolean status = eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), |
+ egl_image_for_unbind_); |
+ |
+ if (success == EGL_FALSE || status == EGL_FALSE) { |
EGLint error = eglGetError(); |
LOG(ERROR) << "Error destroying EGLImage: " << error; |
} |
egl_image_ = EGL_NO_IMAGE_KHR; |
+ egl_image_for_unbind_ = EGL_NO_IMAGE_KHR; |
+ |
+ if (texture_id_) { |
+ glDeleteTextures(1, &texture_id_); |
+ texture_id_ = 0; |
+ } |
} |
gfx::Size GLImageEGL::GetSize() { |
@@ -108,16 +119,32 @@ void GLImageEGL::DidUseTexImage() { |
if (!release_after_use_) |
return; |
- char zero[4] = { 0, }; |
- glTexImage2D(target_, |
- 0, |
- GL_RGBA, |
- 1, |
- 1, |
- 0, |
- GL_RGBA, |
- GL_UNSIGNED_BYTE, |
- &zero); |
+ if (!egl_image_for_unbind_) { |
+ if (!texture_id_) |
reveman
2014/03/20 13:02:05
this can be DCHECK_EQ(0u, texture_id_)
|
+ glGenTextures(1, &texture_id_); |
+ |
+ ScopedTextureBinder texture_binder(GL_TEXTURE_2D, texture_id_); |
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
+ |
+ char zero[4] = {0, }; |
+ glTexImage2D( |
+ GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &zero); |
+ |
+ EGLint attrs[] = {EGL_GL_TEXTURE_LEVEL_KHR, 0, // mip-level. |
+ EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE}; |
+ EGLImageKHR egl_image_for_unbind_ = |
+ eglCreateImageKHR(eglGetCurrentDisplay(), |
+ eglGetCurrentContext(), |
+ EGL_GL_TEXTURE_2D_KHR, |
+ reinterpret_cast<EGLClientBuffer>(texture_id_), |
+ attrs); |
+ DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_for_unbind_) |
+ << "Error creating EGLImage: " << eglGetError(); |
+ } |
+ glEGLImageTargetTexture2DOES(target_, egl_image_for_unbind_); |
+ DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
} |
void GLImageEGL::WillModifyTexImage() { |