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

Side by Side Diff: gpu/command_buffer/common/gles2_cmd_utils.cc

Issue 1028333002: Chromium -> Mojo roll. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 9 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
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 // This file is here so other GLES2 related files can have a common set of 5 // This file is here so other GLES2 related files can have a common set of
6 // includes where appropriate. 6 // includes where appropriate.
7 7
8 #include <sstream> 8 #include <sstream>
9 #include <GLES2/gl2.h> 9 #include <GLES2/gl2.h>
10 #include <GLES2/gl2ext.h> 10 #include <GLES2/gl2ext.h>
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 case GL_RED_INTEGER: 397 case GL_RED_INTEGER:
398 return 1; 398 return 1;
399 default: 399 default:
400 return 0; 400 return 0;
401 } 401 }
402 } 402 }
403 403
404 // Return the number of bytes per element, based on the element type. 404 // Return the number of bytes per element, based on the element type.
405 int BytesPerElement(int type) { 405 int BytesPerElement(int type) {
406 switch (type) { 406 switch (type) {
407 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
408 return 8;
407 case GL_FLOAT: 409 case GL_FLOAT:
408 case GL_UNSIGNED_INT_24_8_OES: 410 case GL_UNSIGNED_INT_24_8_OES:
409 case GL_UNSIGNED_INT: 411 case GL_UNSIGNED_INT:
410 case GL_UNSIGNED_INT_2_10_10_10_REV: 412 case GL_UNSIGNED_INT_2_10_10_10_REV:
411 case GL_UNSIGNED_INT_10F_11F_11F_REV: 413 case GL_UNSIGNED_INT_10F_11F_11F_REV:
412 case GL_UNSIGNED_INT_5_9_9_9_REV: 414 case GL_UNSIGNED_INT_5_9_9_9_REV:
413 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
414 return 4; 415 return 4;
415 case GL_HALF_FLOAT_OES: 416 case GL_HALF_FLOAT_OES:
416 case GL_UNSIGNED_SHORT: 417 case GL_UNSIGNED_SHORT:
417 case GL_SHORT: 418 case GL_SHORT:
418 case GL_UNSIGNED_SHORT_5_6_5: 419 case GL_UNSIGNED_SHORT_5_6_5:
419 case GL_UNSIGNED_SHORT_4_4_4_4: 420 case GL_UNSIGNED_SHORT_4_4_4_4:
420 case GL_UNSIGNED_SHORT_5_5_5_1: 421 case GL_UNSIGNED_SHORT_5_5_5_1:
421 return 2; 422 return 2;
422 case GL_UNSIGNED_BYTE: 423 case GL_UNSIGNED_BYTE:
423 case GL_BYTE: 424 case GL_BYTE:
424 return 1; 425 return 1;
425 default: 426 default:
426 return 0; 427 return 0;
427 } 428 }
428 } 429 }
429 430
430 } // anonymous namespace 431 } // anonymous namespace
431 432
432 uint32 GLES2Util::ComputeImageGroupSize(int format, int type) { 433 uint32 GLES2Util::ComputeImageGroupSize(int format, int type) {
433 return BytesPerElement(type) * ElementsPerGroup(format, type); 434 int bytes_per_element = BytesPerElement(type);
435 DCHECK_GE(8, bytes_per_element);
436 int elements_per_group = ElementsPerGroup(format, type);
437 DCHECK_GE(4, elements_per_group);
438 return bytes_per_element * elements_per_group;
434 } 439 }
435 440
436 bool GLES2Util::ComputeImagePaddedRowSize( 441 bool GLES2Util::ComputeImagePaddedRowSize(
437 int width, int format, int type, int unpack_alignment, 442 int width, int format, int type, int unpack_alignment,
438 uint32* padded_row_size) { 443 uint32* padded_row_size) {
444 DCHECK(unpack_alignment == 1 || unpack_alignment == 2 ||
445 unpack_alignment == 4 || unpack_alignment == 8);
439 uint32 bytes_per_group = ComputeImageGroupSize(format, type); 446 uint32 bytes_per_group = ComputeImageGroupSize(format, type);
440 uint32 unpadded_row_size; 447 uint32 unpadded_row_size;
441 if (!SafeMultiplyUint32(width, bytes_per_group, &unpadded_row_size)) { 448 if (!SafeMultiplyUint32(width, bytes_per_group, &unpadded_row_size)) {
442 return false; 449 return false;
443 } 450 }
444 uint32 temp; 451 uint32 temp;
445 if (!SafeAddUint32(unpadded_row_size, unpack_alignment - 1, &temp)) { 452 if (!SafeAddUint32(unpadded_row_size, unpack_alignment - 1, &temp)) {
446 return false; 453 return false;
447 } 454 }
448 *padded_row_size = (temp / unpack_alignment) * unpack_alignment; 455 *padded_row_size = (temp / unpack_alignment) * unpack_alignment;
449 return true; 456 return true;
450 } 457 }
451 458
452 // Returns the amount of data glTexImage*D or glTexSubImage*D will access. 459 // Returns the amount of data glTexImage*D or glTexSubImage*D will access.
453 bool GLES2Util::ComputeImageDataSizes( 460 bool GLES2Util::ComputeImageDataSizes(
454 int width, int height, int depth, int format, int type, 461 int width, int height, int depth, int format, int type,
455 int unpack_alignment, uint32* size, uint32* ret_unpadded_row_size, 462 int unpack_alignment, uint32* size, uint32* ret_unpadded_row_size,
456 uint32* ret_padded_row_size) { 463 uint32* ret_padded_row_size) {
464 DCHECK(unpack_alignment == 1 || unpack_alignment == 2 ||
465 unpack_alignment == 4 || unpack_alignment == 8);
457 uint32 bytes_per_group = ComputeImageGroupSize(format, type); 466 uint32 bytes_per_group = ComputeImageGroupSize(format, type);
458 uint32 row_size; 467 uint32 row_size;
459 if (!SafeMultiplyUint32(width, bytes_per_group, &row_size)) { 468 if (!SafeMultiplyUint32(width, bytes_per_group, &row_size)) {
460 return false; 469 return false;
461 } 470 }
462 uint32 num_of_rows; 471 uint32 num_of_rows;
463 if (!SafeMultiplyUint32(height, depth, &num_of_rows)) { 472 if (!SafeMultiplyUint32(height, depth, &num_of_rows)) {
464 return false; 473 return false;
465 } 474 }
466 if (num_of_rows > 1) { 475 if (num_of_rows > 1) {
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 } 1098 }
1090 1099
1091 return true; 1100 return true;
1092 } 1101 }
1093 1102
1094 #include "gpu/command_buffer/common/gles2_cmd_utils_implementation_autogen.h" 1103 #include "gpu/command_buffer/common/gles2_cmd_utils_implementation_autogen.h"
1095 1104
1096 } // namespace gles2 1105 } // namespace gles2
1097 } // namespace gpu 1106 } // namespace gpu
1098 1107
OLDNEW
« no previous file with comments | « gpu/command_buffer/common/gles2_cmd_utils.h ('k') | gpu/command_buffer/common/gles2_cmd_utils_implementation_autogen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698