diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc index 1c5abf4d01a29..f356e2180c539 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder.cc +++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc @@ -16075,6 +16075,27 @@ void GLES2DecoderImpl::TexStorageImpl(GLenum target, compatibility_internal_format = format_info->decompressed_internal_format; } + // TODO(zmo): We might need to emulate TexStorage using TexImage or + // CompressedTexImage on Mac OSX where we expose ES3 APIs when the underlying + // driver is lower than 4.2 and ARB_texture_storage extension doesn't exist. + LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(function_name); + if (dimension == ContextState::k2D) { + api()->glTexStorage2DEXTFn(target, levels, compatibility_internal_format, + width, height); + } else { + api()->glTexStorage3DFn(target, levels, compatibility_internal_format, + width, height, depth); + } + GLenum error = LOCAL_PEEK_GL_ERROR(function_name); + if (error != GL_NO_ERROR) { + // The driver rejected the allocation. Do NOT update the decoder-side + // LevelInfo / immutable flag, otherwise subsequent TexSubImage bounds + // checks (Texture::ValidForTexture) would validate against dimensions + // that the driver never allocated, allowing oversized writes to be + // forwarded to the native driver. + return; + } + { GLsizei level_width = width; GLsizei level_height = height; @@ -16103,17 +16124,6 @@ void GLES2DecoderImpl::TexStorageImpl(GLenum target, texture->ApplyFormatWorkarounds(feature_info_.get()); texture->SetImmutable(true, true); } - - // TODO(zmo): We might need to emulate TexStorage using TexImage or - // CompressedTexImage on Mac OSX where we expose ES3 APIs when the underlying - // driver is lower than 4.2 and ARB_texture_storage extension doesn't exist. - if (dimension == ContextState::k2D) { - api()->glTexStorage2DEXTFn(target, levels, compatibility_internal_format, - width, height); - } else { - api()->glTexStorage3DFn(target, levels, compatibility_internal_format, - width, height, depth); - } } void GLES2DecoderImpl::DoTexStorage2DEXT(GLenum target,