Chromium Code Reviews| Index: ui/gl/gl_image_shm.cc |
| diff --git a/ui/gl/gl_image_shm.cc b/ui/gl/gl_image_shm.cc |
| index 076b1fcb79379acb8e21d8fa2481d645500e4179..c5dc77e203ab2941d34518b6cb0e609c9e52ae21 100644 |
| --- a/ui/gl/gl_image_shm.cc |
| +++ b/ui/gl/gl_image_shm.cc |
| @@ -6,7 +6,7 @@ |
| #include "base/debug/trace_event.h" |
| #include "base/process/process_handle.h" |
| -#include "ui/gl/gl_bindings.h" |
| +#include "ui/gl/gl_surface_egl.h" |
| namespace gfx { |
| @@ -92,10 +92,19 @@ bool GLImageShm::Initialize(gfx::GpuMemoryBufferHandle buffer) { |
| shared_memory_.reset( |
| new base::SharedMemory(duped_shared_memory_handle, true)); |
| + |
| + // Setup fallback option (for OES texture). |
| + texture_id_ = 0; |
| + egl_imagekhr_ = EGL_NO_IMAGE_KHR; |
|
reveman
2014/03/13 15:52:40
please initialize these in the ctor instead.
|
| + |
| return true; |
| } |
| void GLImageShm::Destroy() { |
| + if (egl_imagekhr_ != EGL_NO_IMAGE_KHR) |
| + eglDestroyImageKHR(eglGetCurrentDisplay(), egl_imagekhr_); |
| + if (texture_id_) |
| + glDeleteTextures(1, &texture_id_); |
| } |
| gfx::Size GLImageShm::GetSize() { |
| @@ -114,17 +123,52 @@ bool GLImageShm::BindTexImage(unsigned target) { |
| return false; |
| } |
| - DCHECK(shared_memory_->memory()); |
| - glTexImage2D(target, |
| - 0, // mip level |
| - TextureFormat(internalformat_), |
| - size_.width(), |
| - size_.height(), |
| - 0, // border |
| - DataFormat(internalformat_), |
| - DataType(internalformat_), |
| - shared_memory_->memory()); |
| - |
| + if (target == GL_TEXTURE_2D) { |
|
reveman
2014/03/13 15:52:40
this should be "target != GL_TEXTURE_EXTERNAL_OES"
|
| + DCHECK(shared_memory_->memory()); |
| + glTexImage2D(target, |
| + 0, // mip level |
| + TextureFormat(internalformat_), |
| + size_.width(), |
| + size_.height(), |
| + 0, // border |
| + DataFormat(internalformat_), |
| + DataType(internalformat_), |
| + shared_memory_->memory()); |
| + } else { |
| + glGenTextures(1, &texture_id_); |
|
reveman
2014/03/13 15:52:40
you're leaking textures and egl images by doing th
|
| + glActiveTexture(GL_TEXTURE0); |
| + glBindTexture(GL_TEXTURE_2D, texture_id_); |
|
reveman
2014/03/13 15:52:40
all the GL state you change in this function need
|
| + 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); |
| + |
| + DCHECK(shared_memory_->memory()); |
| + glTexImage2D(GL_TEXTURE_2D, |
| + 0, // mip level |
| + TextureFormat(internalformat_), |
| + size_.width(), |
| + size_.height(), |
| + 0, // border |
| + DataFormat(internalformat_), |
| + DataType(internalformat_), |
| + shared_memory_->memory()); |
|
reveman
2014/03/13 15:52:40
this is exactly the same as above. can you refacto
|
| + |
| + EGLint egl_attrib_list[] = {EGL_GL_TEXTURE_LEVEL_KHR, 0, // mip-level. |
| + EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE}; |
| + egl_imagekhr_ = |
| + eglCreateImageKHR(eglGetCurrentDisplay(), |
| + eglGetCurrentContext(), |
| + EGL_GL_TEXTURE_2D_KHR, |
| + reinterpret_cast<EGLClientBuffer>(texture_id_), |
| + egl_attrib_list); |
| + if (egl_imagekhr_ == EGL_NO_IMAGE_KHR) { |
| + EGLint error = eglGetError(); |
| + LOG(ERROR) << "Error creating EGLImage: " << error; |
| + return false; |
|
reveman
2014/03/13 15:52:40
shared_memory_->Unmap() is never called when you r
|
| + } |
| + glBindTexture(GL_TEXTURE_2D, texture_id_); |
| + glEGLImageTargetTexture2DOES(target, egl_imagekhr_); |
| + } |
| shared_memory_->Unmap(); |
| return true; |
| } |