Cherry-pick: Work around broken GL_TEXTURE_BINDING_EXTERNAL_OES query
Cherry-pick of Chromium crrev.com/r229254
BUG: 11392857
Conflicts:
content/common/gpu/stream_texture_manager_android.cc
Original description:
glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &texture_id) returns
GL_INVALID_ENUM on older Android NVIDIA drivers.
The reason for the query is to restore correct texture bindings,
since SurfaceTexture.updateTexImage() implies a call to glBindTexture().
Since we now only call this before drawing, we can just set the correct
active texture unit (which gets restored after draw).
Change-Id: Ideb06f7dc97ee0b870e67ceb10bc8883b3127df5
diff --git a/content/common/gpu/stream_texture_manager_android.cc b/content/common/gpu/stream_texture_manager_android.cc
index 3462fe2..2752eae 100644
--- a/content/common/gpu/stream_texture_manager_android.cc
+++ b/content/common/gpu/stream_texture_manager_android.cc
@@ -27,10 +27,7 @@
}
void StreamTextureManagerAndroid::StreamTextureAndroid::Update() {
- GLint texture_id = 0;
- glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &texture_id);
surface_texture_bridge_->UpdateTexImage();
- glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture_id);
if (matrix_callback_.is_null())
return;
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc
index 44f7674..20c75d4 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder.cc
+++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc
@@ -1403,8 +1403,8 @@
void RestoreStateForAttrib(GLuint attrib);
// If texture is a stream texture, this will update the stream to the newest
- // buffer.
- void UpdateStreamTextureIfNeeded(Texture* texture);
+ // buffer and bind the texture implicitly.
+ void UpdateStreamTextureIfNeeded(Texture* texture, GLuint texture_unit_index);
// Returns false if unrenderable textures were replaced.
bool PrepareTexturesForRender();
@@ -5650,13 +5650,16 @@
std::string("PERFORMANCE WARNING: ") + msg);
}
-void GLES2DecoderImpl::UpdateStreamTextureIfNeeded(Texture* texture) {
+void GLES2DecoderImpl::UpdateStreamTextureIfNeeded(Texture* texture,
+ GLuint texture_unit_index) {
if (texture && texture->IsStreamTexture()) {
DCHECK(stream_texture_manager());
StreamTexture* stream_tex =
stream_texture_manager()->LookupStreamTexture(texture->service_id());
- if (stream_tex)
+ if (stream_tex) {
+ glActiveTexture(GL_TEXTURE0 + texture_unit_index);
stream_tex->Update();
+ }
}
}
@@ -5682,7 +5685,7 @@
TextureRef* texture =
texture_unit.GetInfoForSamplerType(uniform_info->type).get();
if (texture)
- UpdateStreamTextureIfNeeded(texture->texture());
+ UpdateStreamTextureIfNeeded(texture->texture(), texture_unit_index);
if (have_unrenderable_textures &&
(!texture || !texture_manager()->CanRender(texture))) {
textures_set = true;
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc b/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc
index 906eb88..14acb40 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc
+++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc
@@ -5759,6 +5759,9 @@
EXPECT_CALL(*stream_texture_manager(), LookupStreamTexture(kServiceTextureId))
.WillOnce(Return(&stream_texture))
.RetiresOnSaturation();
+ EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
+ .Times(1)
+ .RetiresOnSaturation();
EXPECT_CALL(stream_texture, Update())
.Times(1)
.RetiresOnSaturation();