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

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

Issue 761903003: Update from https://crrev.com/306655 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 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>
11 #include <GLES2/gl2extchromium.h> 11 #include <GLES2/gl2extchromium.h>
12 #include <GLES3/gl3.h>
12 13
14 #include "base/numerics/safe_math.h"
13 #include "gpu/command_buffer/common/gles2_cmd_format.h" 15 #include "gpu/command_buffer/common/gles2_cmd_format.h"
14 #include "gpu/command_buffer/common/gles2_cmd_utils.h" 16 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
15 17
16 namespace gpu { 18 namespace gpu {
17 namespace gles2 { 19 namespace gles2 {
18 20
19 namespace gl_error_bit { 21 namespace gl_error_bit {
20 enum GLErrorBit { 22 enum GLErrorBit {
21 kNoError = 0, 23 kNoError = 0,
22 kInvalidEnum = (1 << 0), 24 kInvalidEnum = (1 << 0),
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 return 1; 355 return 1;
354 default: 356 default:
355 break; 357 break;
356 } 358 }
357 359
358 switch (format) { 360 switch (format) {
359 case GL_RGB: 361 case GL_RGB:
360 case GL_SRGB_EXT: 362 case GL_SRGB_EXT:
361 return 3; 363 return 3;
362 case GL_LUMINANCE_ALPHA: 364 case GL_LUMINANCE_ALPHA:
365 case GL_RG_EXT:
363 return 2; 366 return 2;
364 case GL_RGBA: 367 case GL_RGBA:
365 case GL_BGRA_EXT: 368 case GL_BGRA_EXT:
366 case GL_SRGB_ALPHA_EXT: 369 case GL_SRGB_ALPHA_EXT:
367 return 4; 370 return 4;
368 case GL_ALPHA: 371 case GL_ALPHA:
369 case GL_LUMINANCE: 372 case GL_LUMINANCE:
370 case GL_DEPTH_COMPONENT: 373 case GL_DEPTH_COMPONENT:
371 case GL_DEPTH_COMPONENT24_OES: 374 case GL_DEPTH_COMPONENT24_OES:
372 case GL_DEPTH_COMPONENT32_OES: 375 case GL_DEPTH_COMPONENT32_OES:
373 case GL_DEPTH_COMPONENT16: 376 case GL_DEPTH_COMPONENT16:
374 case GL_DEPTH24_STENCIL8_OES: 377 case GL_DEPTH24_STENCIL8_OES:
375 case GL_DEPTH_STENCIL_OES: 378 case GL_DEPTH_STENCIL_OES:
379 case GL_RED_EXT:
376 return 1; 380 return 1;
377 default: 381 default:
378 return 0; 382 return 0;
379 } 383 }
380 } 384 }
381 385
382 // Return the number of bytes per element, based on the element type. 386 // Return the number of bytes per element, based on the element type.
383 int BytesPerElement(int type) { 387 int BytesPerElement(int type) {
384 switch (type) { 388 switch (type) {
385 case GL_FLOAT: 389 case GL_FLOAT:
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 case GL_DEPTH_COMPONENT32_OES: 701 case GL_DEPTH_COMPONENT32_OES:
698 case GL_DEPTH_COMPONENT24_OES: 702 case GL_DEPTH_COMPONENT24_OES:
699 case GL_DEPTH_COMPONENT16: 703 case GL_DEPTH_COMPONENT16:
700 case GL_DEPTH_COMPONENT: 704 case GL_DEPTH_COMPONENT:
701 return kDepth; 705 return kDepth;
702 case GL_STENCIL_INDEX8: 706 case GL_STENCIL_INDEX8:
703 return kStencil; 707 return kStencil;
704 case GL_DEPTH_STENCIL_OES: 708 case GL_DEPTH_STENCIL_OES:
705 case GL_DEPTH24_STENCIL8_OES: 709 case GL_DEPTH24_STENCIL8_OES:
706 return kDepth | kStencil; 710 return kDepth | kStencil;
711 case GL_RED_EXT:
712 return kRed;
713 case GL_RG_EXT:
714 return kRed | kGreen;
707 default: 715 default:
708 return 0x0000; 716 return 0x0000;
709 } 717 }
710 } 718 }
711 719
712 uint32 GLES2Util::GetChannelsNeededForAttachmentType( 720 uint32 GLES2Util::GetChannelsNeededForAttachmentType(
713 int type, uint32 max_color_attachments) { 721 int type, uint32 max_color_attachments) {
714 switch (type) { 722 switch (type) {
715 case GL_DEPTH_ATTACHMENT: 723 case GL_DEPTH_ATTACHMENT:
716 return kDepth; 724 return kDepth;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 return GetStringEnum(value); 771 return GetStringEnum(value);
764 } 772 }
765 773
766 bool GLES2Util::ParseUniformName( 774 bool GLES2Util::ParseUniformName(
767 const std::string& name, 775 const std::string& name,
768 size_t* array_pos, 776 size_t* array_pos,
769 int* element_index, 777 int* element_index,
770 bool* getting_array) { 778 bool* getting_array) {
771 bool getting_array_location = false; 779 bool getting_array_location = false;
772 size_t open_pos = std::string::npos; 780 size_t open_pos = std::string::npos;
773 int index = 0; 781 base::CheckedNumeric<int> index = 0;
774 if (name[name.size() - 1] == ']') { 782 if (name[name.size() - 1] == ']') {
775 if (name.size() < 3) { 783 if (name.size() < 3) {
776 return false; 784 return false;
777 } 785 }
778 open_pos = name.find_last_of('['); 786 open_pos = name.find_last_of('[');
779 if (open_pos == std::string::npos || 787 if (open_pos == std::string::npos ||
780 open_pos >= name.size() - 2) { 788 open_pos >= name.size() - 2) {
781 return false; 789 return false;
782 } 790 }
783 size_t last = name.size() - 1; 791 size_t last = name.size() - 1;
784 for (size_t pos = open_pos + 1; pos < last; ++pos) { 792 for (size_t pos = open_pos + 1; pos < last; ++pos) {
785 int8 digit = name[pos] - '0'; 793 int8 digit = name[pos] - '0';
786 if (digit < 0 || digit > 9) { 794 if (digit < 0 || digit > 9) {
787 return false; 795 return false;
788 } 796 }
789 index = index * 10 + digit; 797 index = index * 10 + digit;
790 } 798 }
799 if (!index.IsValid()) {
800 return false;
801 }
791 getting_array_location = true; 802 getting_array_location = true;
792 } 803 }
793 *getting_array = getting_array_location; 804 *getting_array = getting_array_location;
794 *element_index = index; 805 *element_index = index.ValueOrDie();
795 *array_pos = open_pos; 806 *array_pos = open_pos;
796 return true; 807 return true;
797 } 808 }
798 809
799 namespace { 810 namespace {
800 811
801 // WebGraphicsContext3DCommandBufferImpl configuration attributes. Those in 812 // WebGraphicsContext3DCommandBufferImpl configuration attributes. Those in
802 // the 16-bit range are the same as used by EGL. Those outside the 16-bit range 813 // the 16-bit range are the same as used by EGL. Those outside the 16-bit range
803 // are unique to Chromium. Attributes are matched using a closest fit algorithm. 814 // are unique to Chromium. Attributes are matched using a closest fit algorithm.
804 815
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 } 953 }
943 954
944 return true; 955 return true;
945 } 956 }
946 957
947 #include "gpu/command_buffer/common/gles2_cmd_utils_implementation_autogen.h" 958 #include "gpu/command_buffer/common/gles2_cmd_utils_implementation_autogen.h"
948 959
949 } // namespace gles2 960 } // namespace gles2
950 } // namespace gpu 961 } // namespace gpu
951 962
OLDNEW
« no previous file with comments | « gpu/command_buffer/common/gles2_cmd_ids_autogen.h ('k') | gpu/command_buffer/common/gles2_cmd_utils_autogen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698