Chromium Code Reviews| Index: ui/gl/gl_image_android_native_buffer.cc |
| diff --git a/ui/gl/gl_image_android_native_buffer.cc b/ui/gl/gl_image_android_native_buffer.cc |
| index 5e311eeef785a3934fc7604e35942498d81cc650..3b9fb3a5ad89aae6d99ae3d8cce2f4bddd920fc6 100644 |
| --- a/ui/gl/gl_image_android_native_buffer.cc |
| +++ b/ui/gl/gl_image_android_native_buffer.cc |
| @@ -18,7 +18,10 @@ GLImageAndroidNativeBuffer::GLImageAndroidNativeBuffer(const gfx::Size& size) |
| texture_id_for_unbind_(0) { |
| } |
| -GLImageAndroidNativeBuffer::~GLImageAndroidNativeBuffer() { Destroy(); } |
| +GLImageAndroidNativeBuffer::~GLImageAndroidNativeBuffer() { |
| + DCHECK_EQ(EGL_NO_IMAGE_KHR, egl_image_); |
| + DCHECK_EQ(0u, texture_id_for_unbind_); |
| +} |
| bool GLImageAndroidNativeBuffer::Initialize(EGLClientBuffer native_buffer) { |
| EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE}; |
| @@ -26,22 +29,27 @@ bool GLImageAndroidNativeBuffer::Initialize(EGLClientBuffer native_buffer) { |
| EGL_NATIVE_BUFFER_ANDROID, native_buffer, attrs); |
| } |
| -void GLImageAndroidNativeBuffer::Destroy() { |
| +void GLImageAndroidNativeBuffer::Destroy(bool have_context) { |
| if (egl_image_for_unbind_ != EGL_NO_IMAGE_KHR) { |
| eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), |
| egl_image_for_unbind_); |
| egl_image_for_unbind_ = EGL_NO_IMAGE_KHR; |
| } |
| + |
| if (texture_id_for_unbind_) { |
| - glDeleteTextures(1, &texture_id_for_unbind_); |
| - texture_id_for_unbind_ = 0; |
| + if (have_context) |
| + glDeleteTextures(1, &texture_id_for_unbind_); |
| + texture_id_for_unbind_ = 0u; |
| } |
| - GLImageEGL::Destroy(); |
| + GLImageEGL::Destroy(have_context); |
| } |
| bool GLImageAndroidNativeBuffer::BindTexImage(unsigned target) { |
| - DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_); |
| + if (egl_image_ == EGL_NO_IMAGE_KHR) { |
| + LOG(ERROR) << "Uninitialized image cannot be bound to texture"; |
| + return false; |
| + } |
|
reveman
2014/07/25 19:00:23
Hm, maybe all these should be DCHECKs after all. I
sohanjg
2014/07/26 10:42:23
Done.
|
| if (target == GL_TEXTURE_RECTANGLE_ARB) { |
| LOG(ERROR) << "EGLImage cannot be bound to TEXTURE_RECTANGLE_ARB target"; |
| @@ -64,7 +72,10 @@ bool GLImageAndroidNativeBuffer::BindTexImage(unsigned target) { |
| } |
| void GLImageAndroidNativeBuffer::WillUseTexImage() { |
| - DCHECK(egl_image_); |
| + if (egl_image_ == EGL_NO_IMAGE_KHR) { |
|
reveman
2014/07/25 19:00:23
Let's make this DCHECK_NE(EGL_NO_IMAGE_KHR, egl_im
sohanjg
2014/07/26 10:42:23
Done.
|
| + LOG(ERROR) << "Uninitialized image cannot be used to bind to texture"; |
| + return; |
| + } |
| DCHECK(!in_use_); |
| in_use_ = true; |
| glEGLImageTargetTexture2DOES(target_, egl_image_); |
| @@ -72,6 +83,11 @@ void GLImageAndroidNativeBuffer::WillUseTexImage() { |
| } |
| void GLImageAndroidNativeBuffer::DidUseTexImage() { |
| + if (egl_image_ == EGL_NO_IMAGE_KHR) { |
|
reveman
2014/07/25 19:00:23
DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_) instead
sohanjg
2014/07/26 10:42:23
Done.
|
| + LOG(ERROR) |
| + << "Uninitialized image cannot be used while unbinding to texture"; |
| + return; |
| + } |
| DCHECK(in_use_); |
| in_use_ = false; |