Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Unified Diff: ui/gl/gl_image_shm.cc

Issue 198703002: Add GL_TEXTURE_EXTERNAL_OES as supported texture target for CHROMIUM_map_image. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Save/restore GL states + nits Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« ui/gl/gl_image_shm.h ('K') | « ui/gl/gl_image_shm.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..5f12025179c05b1b04b6273ee3d16f28ccdcb5ae 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 {
@@ -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),
+ egl_image_(EGL_NO_IMAGE_KHR) {}
GLImageShm::~GLImageShm() {
Destroy();
@@ -96,6 +97,10 @@ bool GLImageShm::Initialize(gfx::GpuMemoryBufferHandle buffer) {
}
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 +119,65 @@ 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());
+ glTexImage2D(target,
+ 0, // mip level
+ TextureFormat(internalformat_),
+ size_.width(),
+ size_.height(),
+ 0, // border
+ DataFormat(internalformat_),
+ DataType(internalformat_),
+ shared_memory_->memory());
+ } else {
+ glGenTextures(1, &external_texture_id_);
reveman 2014/03/14 14:06:22 Why did you make external_texture_id_ a member but
sohanjg 2014/03/15 10:03:53 Done. Have reused the creation code. But, they can
+
+ // Save current GL states
+ GLint current_texture_id = 0;
+ glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &current_texture_id);
+ GLint current_active_texture_unit = 0;
+ glGetIntegerv(GL_ACTIVE_TEXTURE, &current_active_texture_unit);
reveman 2014/03/14 14:06:22 Do you have to change active texture?
sohanjg 2014/03/15 10:03:53 Done. Generally before bindTex we do an activeTex
+
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, external_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);
+
+ 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());
+
+ 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) {
+ EGLint error = eglGetError();
+ LOG(ERROR) << "Error creating EGLImage: " << error;
+ shared_memory_->Unmap();
+ return false;
+ }
+ glBindTexture(GL_TEXTURE_2D, external_texture_id_);
+ glEGLImageTargetTexture2DOES(target, egl_image_);
+
+ // Restore GL States and release
+ Destroy();
reveman 2014/03/14 14:06:22 Destory is supposed to release all resources. Not
sohanjg 2014/03/15 10:03:53 Done. Added a new ReleaseEGLImageandTexture functi
+ glBindTexture(target, current_texture_id);
+ glActiveTexture(current_active_texture_unit);
+ }
shared_memory_->Unmap();
return true;
}
« ui/gl/gl_image_shm.h ('K') | « ui/gl/gl_image_shm.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698