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

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

Issue 10916165: Fix SafeAdd and SafeMultiply (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_decoder.h" 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <list> 10 #include <list>
(...skipping 5417 matching lines...) Expand 10 before | Expand all | Expand 10 after
5428 if (info->enabled() && attrib_0_used) { 5428 if (info->enabled() && attrib_0_used) {
5429 return true; 5429 return true;
5430 } 5430 }
5431 5431
5432 // Make a buffer with a single repeated vec4 value enough to 5432 // Make a buffer with a single repeated vec4 value enough to
5433 // simulate the constant value that is supposed to be here. 5433 // simulate the constant value that is supposed to be here.
5434 // This is required to emulate GLES2 on GL. 5434 // This is required to emulate GLES2 on GL.
5435 typedef VertexAttribManager::VertexAttribInfo::Vec4 Vec4; 5435 typedef VertexAttribManager::VertexAttribInfo::Vec4 Vec4;
5436 5436
5437 GLuint num_vertices = max_vertex_accessed + 1; 5437 GLuint num_vertices = max_vertex_accessed + 1;
5438 GLuint size_needed = 0; 5438 uint32 size_needed = 0;
5439 5439
5440 if (num_vertices == 0 || 5440 if (num_vertices == 0 ||
5441 !SafeMultiply(num_vertices, static_cast<GLuint>(sizeof(Vec4)), 5441 !SafeMultiplyUint32(num_vertices, sizeof(Vec4), &size_needed) ||
5442 &size_needed) ||
5443 size_needed > 0x7FFFFFFFU) { 5442 size_needed > 0x7FFFFFFFU) {
5444 SetGLError(GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0"); 5443 SetGLError(GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0");
5445 return false; 5444 return false;
5446 } 5445 }
5447 5446
5448 PerformanceWarning( 5447 PerformanceWarning(
5449 "Attribute 0 is disabled. This has signficant performance penalty"); 5448 "Attribute 0 is disabled. This has signficant performance penalty");
5450 5449
5451 CopyRealGLErrorsToWrapper(); 5450 CopyRealGLErrorsToWrapper();
5452 glBindBuffer(GL_ARRAY_BUFFER, attrib_0_buffer_id_); 5451 glBindBuffer(GL_ARRAY_BUFFER, attrib_0_buffer_id_);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
5542 GLuint max_accessed = info->MaxVertexAccessed(primcount, 5541 GLuint max_accessed = info->MaxVertexAccessed(primcount,
5543 max_vertex_accessed); 5542 max_vertex_accessed);
5544 GLuint num_vertices = max_accessed + 1; 5543 GLuint num_vertices = max_accessed + 1;
5545 if (num_vertices == 0) { 5544 if (num_vertices == 0) {
5546 SetGLError(GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0"); 5545 SetGLError(GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0");
5547 return false; 5546 return false;
5548 } 5547 }
5549 if (attrib_info && 5548 if (attrib_info &&
5550 info->CanAccess(max_accessed) && 5549 info->CanAccess(max_accessed) &&
5551 info->type() == GL_FIXED) { 5550 info->type() == GL_FIXED) {
5552 GLuint elements_used = 0; 5551 uint32 elements_used = 0;
5553 if (!SafeMultiply(num_vertices, 5552 if (!SafeMultiplyUint32(num_vertices, info->size(), &elements_used) ||
5554 static_cast<GLuint>(info->size()), &elements_used) || 5553 !SafeAddUint32(elements_needed, elements_used, &elements_needed)) {
5555 !SafeAdd(elements_needed, elements_used, &elements_needed)) {
5556 SetGLError( 5554 SetGLError(
5557 GL_OUT_OF_MEMORY, function_name, "simulating GL_FIXED attribs"); 5555 GL_OUT_OF_MEMORY, function_name, "simulating GL_FIXED attribs");
5558 return false; 5556 return false;
5559 } 5557 }
5560 } 5558 }
5561 } 5559 }
5562 5560
5563 const GLuint kSizeOfFloat = sizeof(float); // NOLINT 5561 const uint32 kSizeOfFloat = sizeof(float); // NOLINT
5564 GLuint size_needed = 0; 5562 uint32 size_needed = 0;
5565 if (!SafeMultiply(elements_needed, kSizeOfFloat, &size_needed) || 5563 if (!SafeMultiplyUint32(elements_needed, kSizeOfFloat, &size_needed) ||
5566 size_needed > 0x7FFFFFFFU) { 5564 size_needed > 0x7FFFFFFFU) {
5567 SetGLError(GL_OUT_OF_MEMORY, function_name, "simulating GL_FIXED attribs"); 5565 SetGLError(GL_OUT_OF_MEMORY, function_name, "simulating GL_FIXED attribs");
5568 return false; 5566 return false;
5569 } 5567 }
5570 5568
5571 CopyRealGLErrorsToWrapper(); 5569 CopyRealGLErrorsToWrapper();
5572 5570
5573 glBindBuffer(GL_ARRAY_BUFFER, fixed_attrib_buffer_id_); 5571 glBindBuffer(GL_ARRAY_BUFFER, fixed_attrib_buffer_id_);
5574 if (static_cast<GLsizei>(size_needed) > fixed_attrib_buffer_size_) { 5572 if (static_cast<GLsizei>(size_needed) > fixed_attrib_buffer_size_) {
5575 glBufferData(GL_ARRAY_BUFFER, size_needed, NULL, GL_DYNAMIC_DRAW); 5573 glBufferData(GL_ARRAY_BUFFER, size_needed, NULL, GL_DYNAMIC_DRAW);
(...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after
6474 SetGLErrorInvalidEnum("glReadPixels", type, "type"); 6472 SetGLErrorInvalidEnum("glReadPixels", type, "type");
6475 return error::kNoError; 6473 return error::kNoError;
6476 } 6474 }
6477 if (width == 0 || height == 0) { 6475 if (width == 0 || height == 0) {
6478 return error::kNoError; 6476 return error::kNoError;
6479 } 6477 }
6480 6478
6481 // Get the size of the current fbo or backbuffer. 6479 // Get the size of the current fbo or backbuffer.
6482 gfx::Size max_size = GetBoundReadFrameBufferSize(); 6480 gfx::Size max_size = GetBoundReadFrameBufferSize();
6483 6481
6484 GLint max_x; 6482 int32 max_x;
6485 GLint max_y; 6483 int32 max_y;
6486 if (!SafeAdd(x, width, &max_x) || !SafeAdd(y, height, &max_y)) { 6484 if (!SafeAddInt32(x, width, &max_x) || !SafeAddInt32(y, height, &max_y)) {
6487 SetGLError(GL_INVALID_VALUE, "glReadPixels", "dimensions out of range"); 6485 SetGLError(GL_INVALID_VALUE, "glReadPixels", "dimensions out of range");
6488 return error::kNoError; 6486 return error::kNoError;
6489 } 6487 }
6490 6488
6491 if (!CheckBoundFramebuffersValid("glReadPixels")) { 6489 if (!CheckBoundFramebuffersValid("glReadPixels")) {
6492 return error::kNoError; 6490 return error::kNoError;
6493 } 6491 }
6494 6492
6495 CopyRealGLErrorsToWrapper(); 6493 CopyRealGLErrorsToWrapper();
6496 6494
(...skipping 2032 matching lines...) Expand 10 before | Expand all | Expand 10 after
8529 // Count up the space needed for the result. 8527 // Count up the space needed for the result.
8530 uint32 num_results = 0; 8528 uint32 num_results = 0;
8531 for (GLuint ii = 0; ii < count; ++ii) { 8529 for (GLuint ii = 0; ii < count; ++ii) {
8532 uint32 num = util_.GLGetNumValuesReturned(enums[ii]); 8530 uint32 num = util_.GLGetNumValuesReturned(enums[ii]);
8533 if (num == 0) { 8531 if (num == 0) {
8534 SetGLErrorInvalidEnum("glGetMulitpleCHROMIUM", enums[ii], "pname"); 8532 SetGLErrorInvalidEnum("glGetMulitpleCHROMIUM", enums[ii], "pname");
8535 return error::kNoError; 8533 return error::kNoError;
8536 } 8534 }
8537 // Num will never be more than 4. 8535 // Num will never be more than 4.
8538 DCHECK_LE(num, 4u); 8536 DCHECK_LE(num, 4u);
8539 if (!SafeAdd(num_results, num, &num_results)) { 8537 if (!SafeAddUint32(num_results, num, &num_results)) {
8540 return error::kOutOfBounds; 8538 return error::kOutOfBounds;
8541 } 8539 }
8542 } 8540 }
8543 8541
8544 uint32 result_size = 0; 8542 uint32 result_size = 0;
8545 if (!SafeMultiplyUint32(num_results, sizeof(GLint), &result_size)) { 8543 if (!SafeMultiplyUint32(num_results, sizeof(GLint), &result_size)) {
8546 return error::kOutOfBounds; 8544 return error::kOutOfBounds;
8547 } 8545 }
8548 8546
8549 if (result_size != static_cast<uint32>(c.size)) { 8547 if (result_size != static_cast<uint32>(c.size)) {
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after
9294 } 9292 }
9295 9293
9296 9294
9297 // Include the auto-generated part of this file. We split this because it means 9295 // Include the auto-generated part of this file. We split this because it means
9298 // we can easily edit the non-auto generated parts right here in this file 9296 // we can easily edit the non-auto generated parts right here in this file
9299 // instead of having to edit some template or the code generator. 9297 // instead of having to edit some template or the code generator.
9300 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 9298 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
9301 9299
9302 } // namespace gles2 9300 } // namespace gles2
9303 } // namespace gpu 9301 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/common/gles2_cmd_utils_unittest.cc ('k') | gpu/command_buffer/service/texture_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698