Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Unified Diff: gpu/command_buffer/service/gles2_cmd_srgb_converter.cc

Issue 2866663002: Fix overflow issue when generateMipmap for srgb texture (Closed)
Patch Set: Modify expectation file Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/test/gpu/gpu_tests/webgl2_conformance_expectations.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gpu/command_buffer/service/gles2_cmd_srgb_converter.cc
diff --git a/gpu/command_buffer/service/gles2_cmd_srgb_converter.cc b/gpu/command_buffer/service/gles2_cmd_srgb_converter.cc
index 5556e9d20739c510b6c51434eff68252f51d2ac1..1f560dd1909b4752948ce5291187d1028fe96280 100644
--- a/gpu/command_buffer/service/gles2_cmd_srgb_converter.cc
+++ b/gpu/command_buffer/service/gles2_cmd_srgb_converter.cc
@@ -423,9 +423,14 @@ void SRGBConverter::GenerateMipmap(const gles2::GLES2Decoder* decoder,
mipmap_levels =
TextureManager::ComputeMipMapCount(target, width, height, depth);
}
- const GLint max_mipmap_available_levels =
- (base_level + mipmap_levels) > max_level ? max_level
- : (base_level + mipmap_levels);
+ GLint max_mipmap_available_level;
+ base::CheckedNumeric<GLint> max = base_level;
+ max = max - 1 + mipmap_levels;
+ if (!max.IsValid() || max.ValueOrDie() > max_level) {
+ max_mipmap_available_level = max_level;
+ } else {
+ max_mipmap_available_level = max.ValueOrDie();
+ }
glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]);
if (feature_info_->ext_color_buffer_float_available() &&
@@ -471,19 +476,20 @@ void SRGBConverter::GenerateMipmap(const gles2::GLES2Decoder* decoder,
width = (width == 1) ? 1 : width >> 1;
height = (height == 1) ? 1 : height >> 1;
- // TODO(yizhou): An optimization. Attach 1 level at a time, once for every
- // iteration of the loop.
- for (GLint level = base_level + 1; level < max_mipmap_available_levels;
+ base::CheckedNumeric<GLint> level = base_level;
+ level += 1;
+ for (; level.IsValid() && level.ValueOrDie() <= max_mipmap_available_level;
++level) {
// copy mipmaps level by level from srgb_converter_textures_[1] to tex
// generate mipmap for tex manually
glBindTexture(GL_TEXTURE_2D, tex->service_id());
if (!tex->IsImmutable()) {
- glTexImage2D(GL_TEXTURE_2D, level, internal_format, width, height, 0,
- format, type, nullptr);
+ glTexImage2D(GL_TEXTURE_2D, level.ValueOrDie(), internal_format, width,
+ height, 0, format, type, nullptr);
}
glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
- GL_TEXTURE_2D, tex->service_id(), level);
+ GL_TEXTURE_2D, tex->service_id(),
+ level.ValueOrDie());
glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]);
glViewport(0, 0, width, height);
« no previous file with comments | « content/test/gpu/gpu_tests/webgl2_conformance_expectations.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698