Chromium Code Reviews| 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 5c3bf03f02ab617cbdce5babeb7d590db2e6520f..595e33dd3caeebce22a8a98a89e59b20e7f9cdf4 100644 |
| --- a/gpu/command_buffer/service/gles2_cmd_decoder.cc |
| +++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc |
| @@ -12193,12 +12193,6 @@ bool GLES2DecoderImpl::ValidateCopyTextureCHROMIUM( |
| return false; |
| } |
| - if (GL_TEXTURE_2D != target) { |
| - LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, |
| - "invalid texture target"); |
| - return false; |
| - } |
| - |
| Texture* source_texture = source_texture_ref->texture(); |
| Texture* dest_texture = dest_texture_ref->texture(); |
| if (source_texture == dest_texture) { |
| @@ -12207,10 +12201,18 @@ bool GLES2DecoderImpl::ValidateCopyTextureCHROMIUM( |
| return false; |
| } |
| - if (dest_texture->target() != GL_TEXTURE_2D || |
| - (source_texture->target() != GL_TEXTURE_2D && |
| - source_texture->target() != GL_TEXTURE_RECTANGLE_ARB && |
| - source_texture->target() != GL_TEXTURE_EXTERNAL_OES)) { |
| + GLenum binding_target = GLES2Util::GLFaceToTarget(target); |
| + if (dest_texture->target() != binding_target || |
| + (GL_TEXTURE_2D != binding_target && |
| + GL_TEXTURE_CUBE_MAP != binding_target)) { |
| + LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, |
| + "invalid texture target"); |
| + return false; |
| + } |
| + |
| + if (source_texture->target() != GL_TEXTURE_2D && |
| + source_texture->target() != GL_TEXTURE_RECTANGLE_ARB && |
| + source_texture->target() != GL_TEXTURE_EXTERNAL_OES) { |
| LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, |
| "invalid texture target binding"); |
| return false; |
| @@ -12382,11 +12384,11 @@ void GLES2DecoderImpl::DoCopyTextureCHROMIUM( |
| GLenum dest_internal_format = internal_format; |
| int dest_width = 0; |
| int dest_height = 0; |
| - bool dest_level_defined = dest_texture->GetLevelSize( |
| - GL_TEXTURE_2D, 0, &dest_width, &dest_height, nullptr); |
| + bool dest_level_defined = |
| + dest_texture->GetLevelSize(target, 0, &dest_width, &dest_height, nullptr); |
| if (dest_level_defined) { |
| - dest_texture->GetLevelType(GL_TEXTURE_2D, 0, &dest_type_previous, |
| + dest_texture->GetLevelType(target, 0, &dest_type_previous, |
| &dest_internal_format); |
| } |
| @@ -12397,22 +12399,21 @@ void GLES2DecoderImpl::DoCopyTextureCHROMIUM( |
| dest_type_previous != dest_type) { |
| // Ensure that the glTexImage2D succeeds. |
| LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTextureCHROMIUM"); |
| - glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); |
| - glTexImage2D(GL_TEXTURE_2D, 0, internal_format, source_width, source_height, |
| - 0, internal_format, dest_type, NULL); |
| + glBindTexture(dest_texture->target(), dest_texture->service_id()); |
| + glTexImage2D(target, 0, internal_format, source_width, source_height, 0, |
| + internal_format, dest_type, NULL); |
| GLenum error = LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM"); |
| if (error != GL_NO_ERROR) { |
| - RestoreCurrentTextureBindings(&state_, GL_TEXTURE_2D); |
| + RestoreCurrentTextureBindings(&state_, dest_texture->target()); |
| return; |
| } |
| texture_manager()->SetLevelInfo( |
| - dest_texture_ref, GL_TEXTURE_2D, 0, internal_format, source_width, |
| + dest_texture_ref, target, 0, internal_format, source_width, |
| source_height, 1, 0, internal_format, dest_type, |
| gfx::Rect(source_width, source_height)); |
| } else { |
| - texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0, |
| - true); |
| + texture_manager()->SetLevelCleared(dest_texture_ref, target, 0, true); |
| } |
| ScopedModifyPixels modify(dest_texture_ref); |
| @@ -12421,8 +12422,8 @@ void GLES2DecoderImpl::DoCopyTextureCHROMIUM( |
| bool unpack_premultiply_alpha_change = |
| (unpack_premultiply_alpha ^ unpack_unmultiply_alpha) != 0; |
| if (image && !unpack_flip_y && !unpack_premultiply_alpha_change) { |
| - glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); |
| - if (image->CopyTexSubImage(GL_TEXTURE_2D, gfx::Point(0, 0), |
| + glBindTexture(dest_texture->target(), dest_texture->service_id()); |
| + if (image->CopyTexSubImage(target, gfx::Point(0, 0), |
| gfx::Rect(0, 0, source_width, source_height))) { |
| return; |
| } |
| @@ -12436,18 +12437,15 @@ void GLES2DecoderImpl::DoCopyTextureCHROMIUM( |
| // TODO(hkuang): get the StreamTexture transform matrix in GPU process |
| // instead of using kIdentityMatrix crbug.com/226218. |
| copy_texture_CHROMIUM_->DoCopyTextureWithTransform( |
| - this, source_texture->target(), source_texture->service_id(), |
| + this, source_texture->target(), source_texture->service_id(), target, |
| dest_texture->service_id(), source_width, source_height, |
| - unpack_flip_y == GL_TRUE, |
| - unpack_premultiply_alpha == GL_TRUE, |
| - unpack_unmultiply_alpha == GL_TRUE, |
| - kIdentityMatrix); |
| + unpack_flip_y == GL_TRUE, unpack_premultiply_alpha == GL_TRUE, |
| + unpack_unmultiply_alpha == GL_TRUE, kIdentityMatrix); |
| } else { |
| copy_texture_CHROMIUM_->DoCopyTexture( |
| this, source_texture->target(), source_texture->service_id(), |
| - source_internal_format, dest_texture->service_id(), internal_format, |
| - source_width, source_height, |
| - unpack_flip_y == GL_TRUE, |
| + source_internal_format, target, dest_texture->service_id(), |
| + internal_format, source_width, source_height, unpack_flip_y == GL_TRUE, |
| unpack_premultiply_alpha == GL_TRUE, |
| unpack_unmultiply_alpha == GL_TRUE); |
| } |
| @@ -12474,6 +12472,10 @@ void GLES2DecoderImpl::DoCopySubTextureCHROMIUM( |
| TextureRef* dest_texture_ref = GetTexture(dest_id); |
| Texture* source_texture = source_texture_ref->texture(); |
| Texture* dest_texture = dest_texture_ref->texture(); |
| + GLenum source_type = 0; |
| + GLenum source_internal_format = 0; |
| + source_texture->GetLevelType(source_texture->target(), 0, &source_type, |
| + &source_internal_format); |
| int source_width = 0; |
| int source_height = 0; |
| gfx::GLImage* image = |
| @@ -12495,6 +12497,13 @@ void GLES2DecoderImpl::DoCopySubTextureCHROMIUM( |
| return; |
| } |
| + if (!source_texture->ValidForTexture(source_texture->target(), 0, x, y, 0, |
| + width, height, 1, source_type)) { |
| + LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTextureCHROMIUM", |
| + "source texture bad dimensions."); |
| + return; |
| + } |
| + |
| // Check that this type of texture is allowed. |
| if (!texture_manager()->ValidForTarget(source_texture->target(), 0, |
| source_width, source_height, 1)) { |
| @@ -12504,28 +12513,17 @@ void GLES2DecoderImpl::DoCopySubTextureCHROMIUM( |
| } |
| } |
| - GLenum source_type = 0; |
| - GLenum source_internal_format = 0; |
| - source_texture->GetLevelType(source_texture->target(), 0, &source_type, |
|
dshwang
2015/08/10 08:04:18
It's existing bug because it's not valid if |image
|
| - &source_internal_format); |
| - if (!source_texture->ValidForTexture(source_texture->target(), 0, x, y, 0, |
| - width, height, 1, source_type)) { |
| - LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTextureCHROMIUM", |
| - "source texture bad dimensions."); |
| - return; |
| - } |
| - |
| GLenum dest_type = 0; |
| GLenum dest_internal_format = 0; |
| - bool dest_level_defined = dest_texture->GetLevelType( |
| - dest_texture->target(), 0, &dest_type, &dest_internal_format); |
| + bool dest_level_defined = |
| + dest_texture->GetLevelType(target, 0, &dest_type, &dest_internal_format); |
| if (!dest_level_defined) { |
| LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glCopySubTextureCHROMIUM", |
| "destination texture is not defined"); |
| return; |
| } |
| - if (!dest_texture->ValidForTexture(dest_texture->target(), 0, xoffset, |
| - yoffset, 0, width, height, 1, dest_type)) { |
| + if (!dest_texture->ValidForTexture(target, 0, xoffset, yoffset, 0, width, |
| + height, 1, dest_type)) { |
| LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTextureCHROMIUM", |
| "destination texture bad dimensions."); |
| return; |
| @@ -12558,8 +12556,8 @@ void GLES2DecoderImpl::DoCopySubTextureCHROMIUM( |
| int dest_width = 0; |
| int dest_height = 0; |
| - bool ok = dest_texture->GetLevelSize( |
| - GL_TEXTURE_2D, 0, &dest_width, &dest_height, nullptr); |
| + bool ok = |
| + dest_texture->GetLevelSize(target, 0, &dest_width, &dest_height, nullptr); |
| DCHECK(ok); |
| if (xoffset != 0 || yoffset != 0 || width != dest_width || |
| height != dest_height) { |
| @@ -12581,8 +12579,7 @@ void GLES2DecoderImpl::DoCopySubTextureCHROMIUM( |
| } |
| } |
| } else { |
| - texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0, |
| - true); |
| + texture_manager()->SetLevelCleared(dest_texture_ref, target, 0, true); |
| } |
| ScopedModifyPixels modify(dest_texture_ref); |
| @@ -12591,8 +12588,8 @@ void GLES2DecoderImpl::DoCopySubTextureCHROMIUM( |
| bool unpack_premultiply_alpha_change = |
| (unpack_premultiply_alpha ^ unpack_unmultiply_alpha) != 0; |
| if (image && !unpack_flip_y && !unpack_premultiply_alpha_change) { |
| - glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); |
| - if (image->CopyTexSubImage(GL_TEXTURE_2D, gfx::Point(xoffset, yoffset), |
| + glBindTexture(dest_texture->target(), dest_texture->service_id()); |
| + if (image->CopyTexSubImage(target, gfx::Point(xoffset, yoffset), |
| gfx::Rect(x, y, width, height))) { |
| return; |
| } |
| @@ -12604,12 +12601,10 @@ void GLES2DecoderImpl::DoCopySubTextureCHROMIUM( |
| // crbug.com/226218. |
| copy_texture_CHROMIUM_->DoCopySubTexture( |
| this, source_texture->target(), source_texture->service_id(), |
| - source_internal_format, dest_texture->service_id(), dest_internal_format, |
| - xoffset, yoffset, x, y, width, height, dest_width, dest_height, |
| - source_width, source_height, |
| - unpack_flip_y == GL_TRUE, |
| - unpack_premultiply_alpha == GL_TRUE, |
| - unpack_unmultiply_alpha == GL_TRUE); |
| + source_internal_format, target, dest_texture->service_id(), |
| + dest_internal_format, xoffset, yoffset, x, y, width, height, dest_width, |
| + dest_height, source_width, source_height, unpack_flip_y == GL_TRUE, |
| + unpack_premultiply_alpha == GL_TRUE, unpack_unmultiply_alpha == GL_TRUE); |
| DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); |
| } |
| @@ -12778,13 +12773,13 @@ void GLES2DecoderImpl::DoCompressedCopyTextureCHROMIUM(GLenum target, |
| // instead of using kIdentityMatrix crbug.com/226218. |
| copy_texture_CHROMIUM_->DoCopyTextureWithTransform( |
| this, source_texture->target(), source_texture->service_id(), |
| - dest_texture->service_id(), source_width, source_height, |
| + GL_TEXTURE_2D, dest_texture->service_id(), source_width, source_height, |
| false, false, false, kIdentityMatrix); |
| } else { |
| copy_texture_CHROMIUM_->DoCopyTexture( |
| this, source_texture->target(), source_texture->service_id(), |
| - source_internal_format, dest_texture->service_id(), GL_RGBA, |
| - source_width, source_height, false, false, false); |
| + source_internal_format, GL_TEXTURE_2D, dest_texture->service_id(), |
| + GL_RGBA, source_width, source_height, false, false, false); |
| } |
| DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); |