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..01bff0ced8684395800a27d0abcbb58e022c555b 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/scoped_binders.h" |
namespace gfx { |
@@ -64,8 +64,9 @@ GLenum BytesPerPixel(unsigned internalformat) { |
GLImageShm::GLImageShm(gfx::Size size, unsigned internalformat) |
: size_(size), |
- internalformat_(internalformat) { |
-} |
+ internalformat_(internalformat), |
+ external_texture_id_(0), |
reveman
2014/03/18 10:41:04
nit: 0u
|
+ egl_image_(EGL_NO_IMAGE_KHR) {} |
GLImageShm::~GLImageShm() { |
Destroy(); |
@@ -95,7 +96,34 @@ bool GLImageShm::Initialize(gfx::GpuMemoryBufferHandle buffer) { |
return true; |
} |
+void GLImageShm::SetGLParameters() { |
+ 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); |
+} |
reveman
2014/03/18 10:41:04
I'd remove this utility function. Just makes the c
|
+ |
+bool GLImageShm::CreateEGLImage() { |
reveman
2014/03/18 10:41:04
I'm not sure this utility function is worth much e
|
+ EGLint egl_attrib_list[] = {EGL_GL_TEXTURE_LEVEL_KHR, 0, // mip-level. |
+ EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE}; |
+ egl_image_ = |
+ eglCreateImageKHR(eglGetCurrentDisplay(), |
+ eglGetCurrentContext(), |
+ EGL_GL_TEXTURE_2D_KHR, |
+ reinterpret_cast<EGLClientBuffer>(external_texture_id_), |
+ egl_attrib_list); |
+ if (egl_image_ == EGL_NO_IMAGE_KHR) { |
reveman
2014/03/18 10:41:04
To keep things simple, could this just be:
DCHECK_
|
+ EGLint error = eglGetError(); |
+ LOG(ERROR) << "Error creating EGLImage: " << error; |
+ return false; |
+ } |
+ return true; |
+} |
+ |
void GLImageShm::Destroy() { |
+ if (egl_image_ != EGL_NO_IMAGE_KHR) |
+ eglDestroyImageKHR(eglGetCurrentDisplay(), egl_image_); |
+ if (external_texture_id_) |
+ glDeleteTextures(1, &external_texture_id_); |
} |
gfx::Size GLImageShm::GetSize() { |
@@ -114,17 +142,44 @@ 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_EXTERNAL_OES) { |
+ DCHECK(shared_memory_->memory()); |
reveman
2014/03/18 10:41:04
move this DCHECK above so it doesn't have to be du
|
+ glTexImage2D(target, |
+ 0, // mip level |
+ TextureFormat(internalformat_), |
+ size_.width(), |
+ size_.height(), |
+ 0, // border |
+ DataFormat(internalformat_), |
+ DataType(internalformat_), |
+ shared_memory_->memory()); |
+ } else { |
+ if (!external_texture_id_) |
+ glGenTextures(1, &external_texture_id_); |
+ |
+ ScopedTextureBinder texture_binder(GL_TEXTURE_2D, external_texture_id_); |
+ SetGLParameters(); |
+ |
+ 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()); |
+ |
+ if (!egl_image_) { |
+ if (!CreateEGLImage()) { |
+ shared_memory_->Unmap(); |
+ return false; |
+ } |
+ } |
+ glBindTexture(GL_TEXTURE_2D, external_texture_id_); |
+ glEGLImageTargetTexture2DOES(target, egl_image_); |
+ } |
shared_memory_->Unmap(); |
return true; |
} |