Index: gpu/command_buffer/service/gles2_cmd_decoder.cc |
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc |
index 49f4fc74411d1b356bb200102ce74d7f6bac8861..28d762cf5328fd9d460da9d93393302b833dc1ed 100644 |
--- a/gpu/command_buffer/service/gles2_cmd_decoder.cc |
+++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc |
@@ -1919,9 +1919,15 @@ class GLES2DecoderImpl : public GLES2Decoder, public ErrorStateClient { |
// state of |texture| is updated to reflect the new state. |
void DoCopyTexImage(Texture* texture, GLenum textarget, gl::GLImage* image); |
- // This will call DoCopyTexImage if texture has an image but that image is |
- // not bound or copied to the texture. |
- void DoCopyTexImageIfNeeded(Texture* texture, GLenum textarget); |
+ // If the texture has an image but that image is not bound or copied to the |
+ // texture, this will first attempt to bind it, and if that fails |
+ // DoCopyTexImage on it. texture_unit is the texture unit it should be bound |
+ // to, or 0 if it doesn't matter - setting it to 0 will cause the previous |
+ // binding to be restored after the operation. This returns true if a copy |
+ // or bind happened. |
+ bool DoBindOrCopyTexImageIfNeeded(Texture* texture, |
+ GLenum textarget, |
+ GLuint texture_unit); |
// Returns false if textures were replaced. |
bool PrepareTexturesForRender(); |
@@ -7780,7 +7786,7 @@ void GLES2DecoderImpl::DoFramebufferTexture2DCommon( |
} |
if (texture_ref) |
- DoCopyTexImageIfNeeded(texture_ref->texture(), textarget); |
+ DoBindOrCopyTexImageIfNeeded(texture_ref->texture(), textarget, 0); |
std::vector<GLenum> attachments; |
if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) { |
@@ -9658,20 +9664,30 @@ void GLES2DecoderImpl::DoCopyTexImage(Texture* texture, |
DCHECK(rv) << "CopyTexImage() failed"; |
} |
-void GLES2DecoderImpl::DoCopyTexImageIfNeeded(Texture* texture, |
- GLenum textarget) { |
+bool GLES2DecoderImpl::DoBindOrCopyTexImageIfNeeded(Texture* texture, |
+ GLenum textarget, |
+ GLuint texture_unit) { |
// Image is already in use if texture is attached to a framebuffer. |
if (texture && !texture->IsAttachedToFramebuffer()) { |
Texture::ImageState image_state; |
gl::GLImage* image = texture->GetLevelImage(textarget, 0, &image_state); |
if (image && image_state == Texture::UNBOUND) { |
ScopedGLErrorSuppressor suppressor( |
- "GLES2DecoderImpl::DoCopyTexImageIfNeeded", GetErrorState()); |
+ "GLES2DecoderImpl::DoBindOrCopyTexImageIfNeeded", GetErrorState()); |
+ if (texture_unit) |
+ glActiveTexture(texture_unit); |
glBindTexture(textarget, texture->service_id()); |
Zhenyao Mo
2017/05/25 17:21:58
I am still concerned. Here we changed the tex bind
|
- DoCopyTexImage(texture, textarget, image); |
- RestoreCurrentTextureBindings(&state_, textarget); |
+ if (image->BindTexImage(textarget)) { |
+ image_state = Texture::BOUND; |
+ } else { |
+ DoCopyTexImage(texture, textarget, image); |
+ } |
+ if (!texture_unit) |
+ RestoreCurrentTextureBindings(&state_, textarget); |
+ return true; |
} |
} |
+ return false; |
} |
void GLES2DecoderImpl::DoCopyBufferSubData(GLenum readtarget, |
@@ -9726,16 +9742,9 @@ bool GLES2DecoderImpl::PrepareTexturesForRender() { |
if (textarget != GL_TEXTURE_CUBE_MAP) { |
Texture* texture = texture_ref->texture(); |
- Texture::ImageState image_state; |
- gl::GLImage* image = |
- texture->GetLevelImage(textarget, 0, &image_state); |
- if (image && image_state == Texture::UNBOUND && |
- !texture->IsAttachedToFramebuffer()) { |
- ScopedGLErrorSuppressor suppressor( |
- "GLES2DecoderImpl::PrepareTexturesForRender", GetErrorState()); |
+ if (DoBindOrCopyTexImageIfNeeded(texture, textarget, |
+ GL_TEXTURE0 + texture_unit_index)) { |
textures_set = true; |
- glActiveTexture(GL_TEXTURE0 + texture_unit_index); |
- DoCopyTexImage(texture, textarget, image); |
continue; |
} |
} |
@@ -16947,7 +16956,7 @@ void GLES2DecoderImpl::DoCopyTextureCHROMIUM( |
return; |
} |
- DoCopyTexImageIfNeeded(source_texture, source_target); |
+ DoBindOrCopyTexImageIfNeeded(source_texture, source_target, 0); |
// GL_TEXTURE_EXTERNAL_OES texture requires that we apply a transform matrix |
// before presenting. |
@@ -17159,7 +17168,7 @@ void GLES2DecoderImpl::DoCopySubTextureCHROMIUM( |
} |
} |
- DoCopyTexImageIfNeeded(source_texture, source_target); |
+ DoBindOrCopyTexImageIfNeeded(source_texture, source_target, 0); |
// GL_TEXTURE_EXTERNAL_OES texture requires apply a transform matrix |
// before presenting. |
@@ -17357,7 +17366,7 @@ void GLES2DecoderImpl::DoCompressedCopyTextureCHROMIUM(GLuint source_id, |
"gpu", |
"GLES2DecoderImpl::DoCompressedCopyTextureCHROMIUM, fallback"); |
- DoCopyTexImageIfNeeded(source_texture, source_texture->target()); |
+ DoBindOrCopyTexImageIfNeeded(source_texture, source_texture->target(), 0); |
// As a fallback, copy into a non-compressed GL_RGBA texture. |
LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(kFunctionName); |