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

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

Issue 1508953002: Implement helper functionalities for computing image size with ES3 settings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 } // anonymous namespace 502 } // anonymous namespace
503 503
504 uint32 GLES2Util::ComputeImageGroupSize(int format, int type) { 504 uint32 GLES2Util::ComputeImageGroupSize(int format, int type) {
505 int bytes_per_element = BytesPerElement(type); 505 int bytes_per_element = BytesPerElement(type);
506 DCHECK_GE(8, bytes_per_element); 506 DCHECK_GE(8, bytes_per_element);
507 int elements_per_group = ElementsPerGroup(format, type); 507 int elements_per_group = ElementsPerGroup(format, type);
508 DCHECK_GE(4, elements_per_group); 508 DCHECK_GE(4, elements_per_group);
509 return bytes_per_element * elements_per_group; 509 return bytes_per_element * elements_per_group;
510 } 510 }
511 511
512 bool GLES2Util::ComputeImagePaddedRowSize( 512 bool GLES2Util::ComputeImageRowSizeHelper(
513 int width, int format, int type, int unpack_alignment, 513 int width, uint32 bytes_per_group, int alignment,
514 uint32* padded_row_size) { 514 uint32* rt_unpadded_row_size, uint32* rt_padded_row_size) {
515 DCHECK(unpack_alignment == 1 || unpack_alignment == 2 || 515 DCHECK(alignment == 1 || alignment == 2 ||
516 unpack_alignment == 4 || unpack_alignment == 8); 516 alignment == 4 || alignment == 8);
517 uint32 bytes_per_group = ComputeImageGroupSize(format, type);
518 uint32 unpadded_row_size; 517 uint32 unpadded_row_size;
519 if (!SafeMultiplyUint32(width, bytes_per_group, &unpadded_row_size)) { 518 if (!SafeMultiplyUint32(width, bytes_per_group, &unpadded_row_size)) {
520 return false; 519 return false;
521 } 520 }
522 uint32 temp; 521 uint32 temp;
523 if (!SafeAddUint32(unpadded_row_size, unpack_alignment - 1, &temp)) { 522 if (!SafeAddUint32(unpadded_row_size, alignment - 1, &temp)) {
524 return false; 523 return false;
525 } 524 }
526 *padded_row_size = (temp / unpack_alignment) * unpack_alignment; 525 uint32 padded_row_size = (temp / alignment) * alignment;
526 if (rt_unpadded_row_size)
527 *rt_unpadded_row_size = unpadded_row_size;
528 if (rt_padded_row_size)
529 *rt_padded_row_size = padded_row_size;
527 return true; 530 return true;
528 } 531 }
529 532
533 bool GLES2Util::ComputeImagePaddedRowSize(
534 int width, int format, int type, int alignment, uint32* padded_row_size) {
535 uint32 bytes_per_group = ComputeImageGroupSize(format, type);
536 return ComputeImageRowSizeHelper(
537 width, bytes_per_group, alignment, nullptr, padded_row_size);
538 }
539
530 // Returns the amount of data glTexImage*D or glTexSubImage*D will access. 540 // Returns the amount of data glTexImage*D or glTexSubImage*D will access.
531 bool GLES2Util::ComputeImageDataSizes( 541 bool GLES2Util::ComputeImageDataSizes(
532 int width, int height, int depth, int format, int type, 542 int width, int height, int depth, int format, int type,
533 int unpack_alignment, uint32* size, uint32* ret_unpadded_row_size, 543 int alignment, uint32* size, uint32* opt_unpadded_row_size,
534 uint32* ret_padded_row_size) { 544 uint32* opt_padded_row_size) {
535 DCHECK(unpack_alignment == 1 || unpack_alignment == 2 || 545 DCHECK(width >= 0 && height >= 0 && height >=0);
536 unpack_alignment == 4 || unpack_alignment == 8); 546 if (width == 0 || height == 0 || depth == 0) {
547 *size = 0;
548 return true;
549 }
550
537 uint32 bytes_per_group = ComputeImageGroupSize(format, type); 551 uint32 bytes_per_group = ComputeImageGroupSize(format, type);
538 uint32 row_size; 552
539 if (!SafeMultiplyUint32(width, bytes_per_group, &row_size)) { 553 uint32 unpadded_row_size;
554 uint32 padded_row_size;
555 if (!ComputeImageRowSizeHelper(width, bytes_per_group, alignment,
556 &unpadded_row_size, &padded_row_size)) {
540 return false; 557 return false;
541 } 558 }
542 uint32 num_of_rows; 559 uint32 num_of_rows;
543 if (!SafeMultiplyUint32(height, depth, &num_of_rows)) { 560 if (!SafeMultiplyUint32(height, depth, &num_of_rows)) {
544 return false; 561 return false;
545 } 562 }
546 if (num_of_rows > 1) { 563 DCHECK(num_of_rows > 0);
547 uint32 temp; 564 uint32 size_of_all_but_last_row;
548 if (!SafeAddUint32(row_size, unpack_alignment - 1, &temp)) { 565 if (!SafeMultiplyUint32((num_of_rows - 1), padded_row_size,
549 return false; 566 &size_of_all_but_last_row)) {
550 } 567 return false;
551 uint32 padded_row_size = (temp / unpack_alignment) * unpack_alignment;
552 uint32 size_of_all_but_last_row;
553 if (!SafeMultiplyUint32((num_of_rows - 1), padded_row_size,
554 &size_of_all_but_last_row)) {
555 return false;
556 }
557 if (!SafeAddUint32(size_of_all_but_last_row, row_size, size)) {
558 return false;
559 }
560 if (ret_padded_row_size) {
561 *ret_padded_row_size = padded_row_size;
562 }
563 } else {
564 *size = row_size;
565 if (ret_padded_row_size) {
566 *ret_padded_row_size = row_size;
567 }
568 } 568 }
569 if (ret_unpadded_row_size) { 569 if (!SafeAddUint32(size_of_all_but_last_row, unpadded_row_size, size)) {
570 *ret_unpadded_row_size = row_size; 570 return false;
571 }
572 if (opt_padded_row_size) {
573 *opt_padded_row_size = padded_row_size;
574 }
575 if (opt_unpadded_row_size) {
576 *opt_unpadded_row_size = unpadded_row_size;
571 } 577 }
572 578
573 return true; 579 return true;
574 } 580 }
575 581
582 bool GLES2Util::ComputeImageDataSizesES3(
583 int width, int height, int depth, int format, int type,
584 const PixelStoreParams& params,
585 uint32_t* size, uint32_t* opt_unpadded_row_size,
586 uint32_t* opt_padded_row_size, uint32_t* opt_skip_size) {
587 DCHECK(width >= 0 && height >= 0 && height >=0);
588 if (width == 0 || height == 0 || depth == 0) {
589 *size = 0;
590 return true;
591 }
592
593 uint32 bytes_per_group = ComputeImageGroupSize(format, type);
594
595 uint32 unpadded_row_size;
596 uint32 padded_row_size;
597 if (!ComputeImageRowSizeHelper(width, bytes_per_group, params.alignment,
598 &unpadded_row_size, &padded_row_size)) {
599 return false;
600 }
601 if (params.row_length > 0 &&
602 !ComputeImageRowSizeHelper(params.row_length, bytes_per_group,
603 params.alignment, nullptr, &padded_row_size)) {
604 // Here we re-compute the padded_row_size, but the unpadded_row_size
605 // isn't affected. That is, the last row isn't affected by ROW_LENGTH.
606 return false;
607 }
608
609 int image_height = params.image_height > 0 ? params.image_height : height;
610 uint32 num_of_rows;
611 if (!SafeMultiplyUint32(image_height, depth - 1, &num_of_rows) ||
612 !SafeAddUint32(num_of_rows, height, &num_of_rows)) {
613 return false;
614 }
615 DCHECK(num_of_rows > 0);
616 uint32 size_of_all_but_last_row;
617 if (!SafeMultiplyUint32((num_of_rows - 1), padded_row_size,
618 &size_of_all_but_last_row)) {
619 return false;
620 }
621 if (!SafeAddUint32(size_of_all_but_last_row, unpadded_row_size, size)) {
622 return false;
623 }
624
625 uint32 skip_size = 0;
626 if (params.skip_images > 0) {
627 uint32 image_size;
628 if (!SafeMultiplyUint32(image_height, padded_row_size, &image_size))
629 return false;
630 if (!SafeMultiplyUint32(image_size, params.skip_images, &skip_size))
631 return false;
632 }
633 if (params.skip_rows > 0) {
634 uint32 temp;
635 if (!SafeMultiplyUint32(padded_row_size, params.skip_rows, &temp))
636 return false;
637 if (!SafeAddUint32(skip_size, temp, &skip_size))
638 return false;
639 }
640 if (params.skip_pixels > 0) {
641 uint32 temp;
642 if (!SafeMultiplyUint32(bytes_per_group, params.skip_pixels, &temp))
643 return false;
644 if (!SafeAddUint32(skip_size, temp, &skip_size))
645 return false;
646 }
647 uint32 total_size;
648 if (!SafeAddUint32(*size, skip_size, &total_size))
649 return false;
650
651 if (opt_padded_row_size) {
652 *opt_padded_row_size = padded_row_size;
653 }
654 if (opt_unpadded_row_size) {
655 *opt_unpadded_row_size = unpadded_row_size;
656 }
657 if (opt_skip_size)
658 *opt_skip_size = skip_size;
659 return true;
660 }
661
576 size_t GLES2Util::RenderbufferBytesPerPixel(int format) { 662 size_t GLES2Util::RenderbufferBytesPerPixel(int format) {
577 switch (format) { 663 switch (format) {
578 case GL_STENCIL_INDEX8: 664 case GL_STENCIL_INDEX8:
579 return 1; 665 return 1;
580 case GL_RGBA4: 666 case GL_RGBA4:
581 case GL_RGB565: 667 case GL_RGB565:
582 case GL_RGB5_A1: 668 case GL_RGB5_A1:
583 case GL_DEPTH_COMPONENT16: 669 case GL_DEPTH_COMPONENT16:
584 return 2; 670 return 2;
585 case GL_RGB: 671 case GL_RGB:
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after
1428 } 1514 }
1429 1515
1430 return true; 1516 return true;
1431 } 1517 }
1432 1518
1433 #include "gpu/command_buffer/common/gles2_cmd_utils_implementation_autogen.h" 1519 #include "gpu/command_buffer/common/gles2_cmd_utils_implementation_autogen.h"
1434 1520
1435 } // namespace gles2 1521 } // namespace gles2
1436 } // namespace gpu 1522 } // namespace gpu
1437 1523
OLDNEW
« no previous file with comments | « gpu/command_buffer/common/gles2_cmd_utils.h ('k') | gpu/command_buffer/common/gles2_cmd_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698