| Index: ui/gl/gl_image_shm.cc
|
| diff --git a/ui/gl/gl_image_shm.cc b/ui/gl/gl_image_shm.cc
|
| index 40ad67a5dc363d480579e42e34b999ce8d293e38..1c45f044e7b42f3b191bc52be73d897193837135 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),
|
| + egl_texture_id_(0u),
|
| + egl_image_(EGL_NO_IMAGE_KHR) {}
|
|
|
| GLImageShm::~GLImageShm() {
|
| Destroy();
|
| @@ -96,6 +97,14 @@ bool GLImageShm::Initialize(gfx::GpuMemoryBufferHandle buffer) {
|
| }
|
|
|
| void GLImageShm::Destroy() {
|
| + if (egl_image_ != EGL_NO_IMAGE_KHR) {
|
| + eglDestroyImageKHR(eglGetCurrentDisplay(), egl_image_);
|
| + egl_image_ = EGL_NO_IMAGE_KHR;
|
| + }
|
| + if (egl_texture_id_) {
|
| + glDeleteTextures(1, &egl_texture_id_);
|
| + egl_texture_id_ = 0;
|
| + }
|
| }
|
|
|
| gfx::Size GLImageShm::GetSize() {
|
| @@ -115,16 +124,50 @@ bool GLImageShm::BindTexImage(unsigned target) {
|
| }
|
|
|
| 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) {
|
| + glTexImage2D(target,
|
| + 0, // mip level
|
| + TextureFormat(internalformat_),
|
| + size_.width(),
|
| + size_.height(),
|
| + 0, // border
|
| + DataFormat(internalformat_),
|
| + DataType(internalformat_),
|
| + shared_memory_->memory());
|
| + } else {
|
| + if (!egl_texture_id_)
|
| + glGenTextures(1, &egl_texture_id_);
|
| +
|
| + ScopedTextureBinder texture_binder(GL_TEXTURE_2D, egl_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);
|
| +
|
| + 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_) {
|
| + 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>(egl_texture_id_),
|
| + egl_attrib_list);
|
| + DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_)
|
| + << "Error creating EGLImage: " << eglGetError();
|
| + }
|
| + glBindTexture(GL_TEXTURE_2D, egl_texture_id_);
|
| + glEGLImageTargetTexture2DOES(target, egl_image_);
|
| + }
|
| shared_memory_->Unmap();
|
| return true;
|
| }
|
|
|