| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/gl/gl_image_android_native_buffer.h" | 5 #include "ui/gl/gl_image_android_native_buffer.h" |
| 6 | 6 |
| 7 #include "ui/gl/gl_surface_egl.h" | 7 #include "ui/gl/gl_surface_egl.h" |
| 8 #include "ui/gl/scoped_binders.h" | 8 #include "ui/gl/scoped_binders.h" |
| 9 | 9 |
| 10 namespace gfx { | 10 namespace gfx { |
| 11 | 11 |
| 12 GLImageAndroidNativeBuffer::GLImageAndroidNativeBuffer(const gfx::Size& size) | 12 GLImageAndroidNativeBuffer::GLImageAndroidNativeBuffer(const gfx::Size& size) |
| 13 : GLImageEGL(size), | 13 : GLImageEGL(size), |
| 14 release_after_use_(false), | 14 release_after_use_(false), |
| 15 in_use_(false), | 15 in_use_(false), |
| 16 target_(0), | 16 target_(0), |
| 17 egl_image_for_unbind_(EGL_NO_IMAGE_KHR), | 17 egl_image_for_unbind_(EGL_NO_IMAGE_KHR), |
| 18 texture_id_for_unbind_(0) { | 18 texture_id_for_unbind_(0) { |
| 19 } | 19 } |
| 20 | 20 |
| 21 GLImageAndroidNativeBuffer::~GLImageAndroidNativeBuffer() { Destroy(); } | 21 GLImageAndroidNativeBuffer::~GLImageAndroidNativeBuffer() { |
| 22 DCHECK_EQ(EGL_NO_IMAGE_KHR, egl_image_); |
| 23 DCHECK_EQ(0u, texture_id_for_unbind_); |
| 24 } |
| 22 | 25 |
| 23 bool GLImageAndroidNativeBuffer::Initialize(EGLClientBuffer native_buffer) { | 26 bool GLImageAndroidNativeBuffer::Initialize(EGLClientBuffer native_buffer) { |
| 24 EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE}; | 27 EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE}; |
| 25 return GLImageEGL::Initialize( | 28 return GLImageEGL::Initialize( |
| 26 EGL_NATIVE_BUFFER_ANDROID, native_buffer, attrs); | 29 EGL_NATIVE_BUFFER_ANDROID, native_buffer, attrs); |
| 27 } | 30 } |
| 28 | 31 |
| 29 void GLImageAndroidNativeBuffer::Destroy() { | 32 void GLImageAndroidNativeBuffer::Destroy(bool have_context) { |
| 30 if (egl_image_for_unbind_ != EGL_NO_IMAGE_KHR) { | 33 if (egl_image_for_unbind_ != EGL_NO_IMAGE_KHR) { |
| 31 eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), | 34 eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), |
| 32 egl_image_for_unbind_); | 35 egl_image_for_unbind_); |
| 33 egl_image_for_unbind_ = EGL_NO_IMAGE_KHR; | 36 egl_image_for_unbind_ = EGL_NO_IMAGE_KHR; |
| 34 } | 37 } |
| 38 |
| 35 if (texture_id_for_unbind_) { | 39 if (texture_id_for_unbind_) { |
| 36 glDeleteTextures(1, &texture_id_for_unbind_); | 40 if (have_context) |
| 37 texture_id_for_unbind_ = 0; | 41 glDeleteTextures(1, &texture_id_for_unbind_); |
| 42 texture_id_for_unbind_ = 0u; |
| 38 } | 43 } |
| 39 | 44 |
| 40 GLImageEGL::Destroy(); | 45 GLImageEGL::Destroy(have_context); |
| 41 } | 46 } |
| 42 | 47 |
| 43 bool GLImageAndroidNativeBuffer::BindTexImage(unsigned target) { | 48 bool GLImageAndroidNativeBuffer::BindTexImage(unsigned target) { |
| 44 DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_); | 49 if (egl_image_ == EGL_NO_IMAGE_KHR) { |
| 50 LOG(ERROR) << "No EGLImage to bind"; |
| 51 return false; |
| 52 } |
| 45 | 53 |
| 46 if (target == GL_TEXTURE_RECTANGLE_ARB) { | 54 if (target == GL_TEXTURE_RECTANGLE_ARB) { |
| 47 LOG(ERROR) << "EGLImage cannot be bound to TEXTURE_RECTANGLE_ARB target"; | 55 LOG(ERROR) << "EGLImage cannot be bound to TEXTURE_RECTANGLE_ARB target"; |
| 48 return false; | 56 return false; |
| 49 } | 57 } |
| 50 | 58 |
| 51 if (target_ && target_ != target) { | 59 if (target_ && target_ != target) { |
| 52 LOG(ERROR) << "EGLImage can only be bound to one target"; | 60 LOG(ERROR) << "EGLImage can only be bound to one target"; |
| 53 return false; | 61 return false; |
| 54 } | 62 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 | 116 |
| 109 glEGLImageTargetTexture2DOES(target_, egl_image_for_unbind_); | 117 glEGLImageTargetTexture2DOES(target_, egl_image_for_unbind_); |
| 110 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 118 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 111 } | 119 } |
| 112 | 120 |
| 113 void GLImageAndroidNativeBuffer::SetReleaseAfterUse() { | 121 void GLImageAndroidNativeBuffer::SetReleaseAfterUse() { |
| 114 release_after_use_ = true; | 122 release_after_use_ = true; |
| 115 } | 123 } |
| 116 | 124 |
| 117 } // namespace gfx | 125 } // namespace gfx |
| OLD | NEW |