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

Side by Side Diff: gpu/command_buffer/service/gles2_cmd_srgb_converter.cc

Issue 2866663002: Fix overflow issue when generateMipmap for srgb texture (Closed)
Patch Set: Address to Zhenyao's feedback 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gpu/command_buffer/service/gles2_cmd_srgb_converter.h" 5 #include "gpu/command_buffer/service/gles2_cmd_srgb_converter.h"
6 6
7 #include "gpu/command_buffer/service/texture_manager.h" 7 #include "gpu/command_buffer/service/texture_manager.h"
8 #include "ui/gl/gl_version_info.h" 8 #include "ui/gl/gl_version_info.h"
9 9
10 namespace { 10 namespace {
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 tex->GetLevelSize(target, base_level, &width, &height, &depth); 416 tex->GetLevelSize(target, base_level, &width, &height, &depth);
417 tex->GetLevelType(target, base_level, &type, &internal_format); 417 tex->GetLevelType(target, base_level, &type, &internal_format);
418 format = TextureManager::ExtractFormatFromStorageFormat(internal_format); 418 format = TextureManager::ExtractFormatFromStorageFormat(internal_format);
419 GLint mipmap_levels; 419 GLint mipmap_levels;
420 if (tex->IsImmutable()) { 420 if (tex->IsImmutable()) {
421 mipmap_levels = tex->GetImmutableLevels(); 421 mipmap_levels = tex->GetImmutableLevels();
422 } else { 422 } else {
423 mipmap_levels = 423 mipmap_levels =
424 TextureManager::ComputeMipMapCount(target, width, height, depth); 424 TextureManager::ComputeMipMapCount(target, width, height, depth);
425 } 425 }
426 const GLint max_mipmap_available_levels = 426 GLint max_mipmap_available_level;
427 (base_level + mipmap_levels) > max_level ? max_level 427 base::CheckedNumeric<GLint> max = base_level;
428 : (base_level + mipmap_levels); 428 max = max - 1 + mipmap_levels;
429 if (!max.IsValid() || max.ValueOrDie() > max_level) {
430 max_mipmap_available_level = max_level;
431 } else {
432 max_mipmap_available_level = max.ValueOrDie();
433 }
429 434
430 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]); 435 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]);
431 if (feature_info_->ext_color_buffer_float_available() && 436 if (feature_info_->ext_color_buffer_float_available() &&
432 feature_info_->oes_texture_float_linear_available()) { 437 feature_info_->oes_texture_float_linear_available()) {
433 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, width, height, 0, GL_RGBA, 438 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, width, height, 0, GL_RGBA,
434 GL_FLOAT, nullptr); 439 GL_FLOAT, nullptr);
435 } else { 440 } else {
436 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, 441 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA,
437 GL_UNSIGNED_BYTE, nullptr); 442 GL_UNSIGNED_BYTE, nullptr);
438 } 443 }
(...skipping 27 matching lines...) Expand all
466 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, srgb_encoder_fbo_); 471 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, srgb_encoder_fbo_);
467 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]); 472 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]);
468 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, 473 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
469 GL_NEAREST_MIPMAP_NEAREST); 474 GL_NEAREST_MIPMAP_NEAREST);
470 475
471 width = (width == 1) ? 1 : width >> 1; 476 width = (width == 1) ? 1 : width >> 1;
472 height = (height == 1) ? 1 : height >> 1; 477 height = (height == 1) ? 1 : height >> 1;
473 478
474 // TODO(yizhou): An optimization. Attach 1 level at a time, once for every 479 // TODO(yizhou): An optimization. Attach 1 level at a time, once for every
475 // iteration of the loop. 480 // iteration of the loop.
476 for (GLint level = base_level + 1; level < max_mipmap_available_levels; 481 for (base::CheckedNumeric<GLint> level = base_level + 1;
Zhenyao Mo 2017/05/10 17:25:48 I am not sure if this can catch the overflow. My
482 level.IsValid() && level.ValueOrDie() <= max_mipmap_available_level;
477 ++level) { 483 ++level) {
478 // copy mipmaps level by level from srgb_converter_textures_[1] to tex 484 // copy mipmaps level by level from srgb_converter_textures_[1] to tex
479 // generate mipmap for tex manually 485 // generate mipmap for tex manually
480 glBindTexture(GL_TEXTURE_2D, tex->service_id()); 486 glBindTexture(GL_TEXTURE_2D, tex->service_id());
481 if (!tex->IsImmutable()) { 487 if (!tex->IsImmutable()) {
482 glTexImage2D(GL_TEXTURE_2D, level, internal_format, width, height, 0, 488 glTexImage2D(GL_TEXTURE_2D, level.ValueOrDie(), internal_format, width,
483 format, type, nullptr); 489 height, 0, format, type, nullptr);
484 } 490 }
485 glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 491 glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
486 GL_TEXTURE_2D, tex->service_id(), level); 492 GL_TEXTURE_2D, tex->service_id(),
493 level.ValueOrDie());
487 494
488 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]); 495 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]);
489 glViewport(0, 0, width, height); 496 glViewport(0, 0, width, height);
490 glDrawArrays(GL_TRIANGLES, 0, 6); 497 glDrawArrays(GL_TRIANGLES, 0, 6);
491 width = (width == 1) ? 1 : width >> 1; 498 width = (width == 1) ? 1 : width >> 1;
492 height = (height == 1) ? 1 : height >> 1; 499 height = (height == 1) ? 1 : height >> 1;
493 } 500 }
494 501
495 // Restore state 502 // Restore state
496 decoder->RestoreAllAttributes(); 503 decoder->RestoreAllAttributes();
497 decoder->RestoreTextureUnitBindings(0); 504 decoder->RestoreTextureUnitBindings(0);
498 decoder->RestoreActiveTexture(); 505 decoder->RestoreActiveTexture();
499 decoder->RestoreProgramBindings(); 506 decoder->RestoreProgramBindings();
500 decoder->RestoreBufferBindings(); 507 decoder->RestoreBufferBindings();
501 decoder->RestoreFramebufferBindings(); 508 decoder->RestoreFramebufferBindings();
502 decoder->RestoreGlobalState(); 509 decoder->RestoreGlobalState();
503 decoder->RestoreTextureState(tex->service_id()); 510 decoder->RestoreTextureState(tex->service_id());
504 } 511 }
505 512
506 } // namespace gles2. 513 } // namespace gles2.
507 } // namespace gpu 514 } // namespace gpu
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698