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

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 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 unpack_alignment == 4 || unpack_alignment == 8); 536 unpack_alignment == 4 || unpack_alignment == 8);
537 uint32 bytes_per_group = ComputeImageGroupSize(format, type); 537 uint32 bytes_per_group = ComputeImageGroupSize(format, type);
538 uint32 row_size; 538 uint32 row_size;
539 if (!SafeMultiplyUint32(width, bytes_per_group, &row_size)) { 539 if (!SafeMultiplyUint32(width, bytes_per_group, &row_size)) {
540 return false; 540 return false;
541 } 541 }
542 uint32 num_of_rows; 542 uint32 num_of_rows;
543 if (!SafeMultiplyUint32(height, depth, &num_of_rows)) { 543 if (!SafeMultiplyUint32(height, depth, &num_of_rows)) {
544 return false; 544 return false;
545 } 545 }
546 if (num_of_rows > 1) { 546 uint32 temp;
547 uint32 temp; 547 if (!SafeAddUint32(row_size, unpack_alignment - 1, &temp)) {
548 if (!SafeAddUint32(row_size, unpack_alignment - 1, &temp)) { 548 return false;
549 return false; 549 }
550 } 550 uint32 padded_row_size = (temp / unpack_alignment) * unpack_alignment;
551 uint32 padded_row_size = (temp / unpack_alignment) * unpack_alignment; 551 uint32 size_of_all_but_last_row;
552 uint32 size_of_all_but_last_row; 552 if (!SafeMultiplyUint32((num_of_rows - 1), padded_row_size,
553 if (!SafeMultiplyUint32((num_of_rows - 1), padded_row_size, 553 &size_of_all_but_last_row)) {
554 &size_of_all_but_last_row)) { 554 return false;
555 return false; 555 }
556 } 556 if (!SafeAddUint32(size_of_all_but_last_row, row_size, size)) {
557 if (!SafeAddUint32(size_of_all_but_last_row, row_size, size)) { 557 return false;
558 return false; 558 }
559 } 559 if (ret_padded_row_size) {
560 if (ret_padded_row_size) { 560 *ret_padded_row_size = 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 } 561 }
569 if (ret_unpadded_row_size) { 562 if (ret_unpadded_row_size) {
570 *ret_unpadded_row_size = row_size; 563 *ret_unpadded_row_size = row_size;
571 } 564 }
572 565
573 return true; 566 return true;
574 } 567 }
575 568
569 bool GLES2Util::ComputeImageDataSizes(
570 int width, int height, int depth, int format, int type,
571 const PixelStoreParams& params,
572 uint32_t* size, uint32_t* unpadded_row_size,
573 uint32_t* padded_row_size, uint32_t* skip_size) {
574 int actual_width = params.row_length > 0 ? params.row_length : width;
piman 2015/12/08 00:06:10 So, technically, the code (whether client-side, or
Zhenyao Mo 2015/12/08 23:39:17 Done. However, I think we still need the ContextS
575 int actual_height = params.image_height > 0 ? params.image_height : height;
576 if (!ComputeImageDataSizes(actual_width, actual_height, depth, format, type,
577 params.alignment,
578 size, unpadded_row_size, padded_row_size)) {
579 return false;
580 }
581
582 uint32 total_skip_size = 0;
583 if (params.skip_images > 0) {
584 uint32 image_size;
585 if (!SafeMultiplyUint32(actual_height, *padded_row_size, &image_size))
586 return false;
587 if (!SafeMultiplyUint32(image_size, params.skip_images, &total_skip_size))
588 return false;
589 }
590 if (params.skip_rows > 0) {
591 uint32 temp;
592 if (!SafeMultiplyUint32(*padded_row_size, params.skip_rows, &temp))
593 return false;
594 if (!SafeAddUint32(total_skip_size, temp, &total_skip_size))
595 return false;
596 }
597 if (params.skip_pixels > 0) {
598 uint32 bytes_per_group = ComputeImageGroupSize(format, type);
599 uint32 temp;
600 if (!SafeMultiplyUint32(bytes_per_group, params.skip_pixels, &temp))
601 return false;
602 if (!SafeAddUint32(total_skip_size, temp, &total_skip_size))
603 return false;
604 }
605 if (!SafeAddUint32(*size, total_skip_size, size))
piman 2015/12/08 00:06:10 I think this is more confusing than useful. Only |
Zhenyao Mo 2015/12/08 23:39:17 OK, I won't write into size, but we still wanna ch
606 return false;
607 if (skip_size)
608 *skip_size = total_skip_size;
609 return true;
610 }
611
576 size_t GLES2Util::RenderbufferBytesPerPixel(int format) { 612 size_t GLES2Util::RenderbufferBytesPerPixel(int format) {
577 switch (format) { 613 switch (format) {
578 case GL_STENCIL_INDEX8: 614 case GL_STENCIL_INDEX8:
579 return 1; 615 return 1;
580 case GL_RGBA4: 616 case GL_RGBA4:
581 case GL_RGB565: 617 case GL_RGB565:
582 case GL_RGB5_A1: 618 case GL_RGB5_A1:
583 case GL_DEPTH_COMPONENT16: 619 case GL_DEPTH_COMPONENT16:
584 return 2; 620 return 2;
585 case GL_RGB: 621 case GL_RGB:
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after
1428 } 1464 }
1429 1465
1430 return true; 1466 return true;
1431 } 1467 }
1432 1468
1433 #include "gpu/command_buffer/common/gles2_cmd_utils_implementation_autogen.h" 1469 #include "gpu/command_buffer/common/gles2_cmd_utils_implementation_autogen.h"
1434 1470
1435 } // namespace gles2 1471 } // namespace gles2
1436 } // namespace gpu 1472 } // namespace gpu
1437 1473
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