Reviewers: reveman,
Message:
PTAL. Thanks
https://codereview.chromium.org/216873003/diff/1/ui/gl/gl_image_shm.cc
File ui/gl/gl_image_shm.cc (right):
https://codereview.chromium.org/216873003/diff/1/ui/gl/gl_image_shm.cc#newcode142
ui/gl/gl_image_shm.cc:142: if (egl_image_ == EGL_NO_IMAGE_KHR) {
Should we add an extra check for egl_texture_id_ being 0.
Description:
Use glTexSubImage2D while binding with GL_TEXTURE_EXTERNAL_OES for
map-image.
In GLImageShm, use glTexSub instead of glTex during binding,
as it is more efficient and avoids gpu-workarounds.
BUG=357493
Please review this at
https://codereview.chromium.org/216873003/
SVN Base:
https://chromium.googlesource.com/chromium/src.git@master
Affected files (+43, -34 lines):
M ui/gl/gl_image_shm.cc
Index: ui/gl/gl_image_shm.cc
diff --git a/ui/gl/gl_image_shm.cc b/ui/gl/gl_image_shm.cc
index
081623ed93d175a7fe593308c641ef4125cb1af6..895c389a4c410eac4796ceb90b4600d3e275e2d5
100644
--- a/ui/gl/gl_image_shm.cc
+++ b/ui/gl/gl_image_shm.cc
@@ -139,45 +139,54 @@ bool GLImageShm::BindTexImage(unsigned target) {
#if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \
defined(USE_OZONE)
if (target == GL_TEXTURE_EXTERNAL_OES) {
- if (egl_image_ != EGL_NO_IMAGE_KHR)
- eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), egl_image_);
-
- if (!egl_texture_id_)
+ if (egl_image_ == EGL_NO_IMAGE_KHR) {
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());
+ }
+
+ EGLint attrs[] = {EGL_GL_TEXTURE_LEVEL_KHR, 0,
EGL_IMAGE_PRESERVED_KHR,
+ EGL_TRUE, EGL_NONE};
+ // Need to pass current EGL rendering context to eglCreateImageKHR
for
+ // target type EGL_GL_TEXTURE_2D_KHR.
+ egl_image_ =
+ eglCreateImageKHR(GLSurfaceEGL::GetHardwareDisplay(),
+ eglGetCurrentContext(),
+ EGL_GL_TEXTURE_2D_KHR,
+
reinterpret_cast<EGLClientBuffer>(egl_texture_id_),
+ attrs);
+ DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_)
+ << "Error creating EGLImage: " << eglGetError();
+
+ glEGLImageTargetTexture2DOES(target, egl_image_);
+ DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
+ } else {
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());
+ glTexSubImage2D(GL_TEXTURE_2D,
+ 0, // mip level
+ 0, // x-offset
+ 0, // y-offset
+ size_.width(),
+ size_.height(),
+ DataFormat(internalformat_),
+ DataType(internalformat_),
+ shared_memory_->memory());
}
- EGLint attrs[] = {EGL_GL_TEXTURE_LEVEL_KHR, 0, EGL_IMAGE_PRESERVED_KHR,
- EGL_TRUE, EGL_NONE};
- // Need to pass current EGL rendering context to eglCreateImageKHR for
- // target type EGL_GL_TEXTURE_2D_KHR.
- egl_image_ =
- eglCreateImageKHR(GLSurfaceEGL::GetHardwareDisplay(),
- eglGetCurrentContext(),
- EGL_GL_TEXTURE_2D_KHR,
-
reinterpret_cast<EGLClientBuffer>(egl_texture_id_),
- attrs);
- DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_)
- << "Error creating EGLImage: " << eglGetError();
-
- glEGLImageTargetTexture2DOES(target, egl_image_);
- DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
-
shared_memory_->Unmap();
return true;
}