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

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: reuse resource creation code + comments 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
« no previous file with comments | « 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..8f7dec5ae45e9e1a5ae86bcfeacf448941f68f0b 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"
reveman 2014/03/17 01:13:38 why is gl_bindings.h not enough?
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();
@@ -95,9 +96,40 @@ bool GLImageShm::Initialize(gfx::GpuMemoryBufferHandle buffer) {
return true;
}
-void GLImageShm::Destroy() {
+void GLImageShm::CreateTexture2D() {
+ glGenTextures(1, &external_texture_id_);
+ 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);
+}
+
+bool GLImageShm::CreateEGLImage() {
+ 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;
+ return false;
+ }
+ return true;
}
+void GLImageShm::ReleaseEGLImageandTexture() {
+ if (egl_image_ != EGL_NO_IMAGE_KHR)
+ eglDestroyImageKHR(eglGetCurrentDisplay(), egl_image_);
+ if (external_texture_id_)
+ glDeleteTextures(1, &external_texture_id_);
+}
+
+void GLImageShm::Destroy() { ReleaseEGLImageandTexture(); }
+
gfx::Size GLImageShm::GetSize() {
return size_;
}
@@ -114,17 +146,45 @@ 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 {
+ // Save current GL state.
+ GLint current_texture_id = 0;
+ glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &current_texture_id);
reveman 2014/03/15 14:08:45 EXTERNAL_OES binding is not the state you're chang
reveman 2014/03/17 01:13:38 Also, use ScopedTextureBinder here instead.
+ CreateTexture2D();
+
+ 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 (!CreateEGLImage()) {
+ shared_memory_->Unmap();
+ return false;
+ }
+ glBindTexture(GL_TEXTURE_2D, external_texture_id_);
+ glEGLImageTargetTexture2DOES(target, egl_image_);
+ // Restore GL State and release.
+ ReleaseEGLImageandTexture();
reveman 2014/03/15 14:08:45 what's the point of having egl_image_ and external
reveman 2014/03/17 01:13:38 Don't get hung up on reusing the egl image though.
+ glBindTexture(target, current_texture_id);
+ }
shared_memory_->Unmap();
return true;
}
« no previous file with comments | « ui/gl/gl_image_shm.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698