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

Side by Side Diff: third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp

Issue 2370703003: Validate internalformat/format/type for uploading DOM elements to texture (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 GL_RGBA8_SNORM, 767 GL_RGBA8_SNORM,
768 GL_RGBA16F, 768 GL_RGBA16F,
769 GL_RGBA32F, 769 GL_RGBA32F,
770 GL_DEPTH_COMPONENT16, 770 GL_DEPTH_COMPONENT16,
771 GL_DEPTH_COMPONENT24, 771 GL_DEPTH_COMPONENT24,
772 GL_DEPTH_COMPONENT32F, 772 GL_DEPTH_COMPONENT32F,
773 GL_DEPTH24_STENCIL8, 773 GL_DEPTH24_STENCIL8,
774 GL_DEPTH32F_STENCIL8, 774 GL_DEPTH32F_STENCIL8,
775 }; 775 };
776 776
777 // ES3 enums supported by TexImageSource
778 static const GLenum kSupportedInternalFormatsTexImageSourceES3[] = {
779 GL_R8,
780 GL_R16F,
781 GL_R32F,
782 GL_R8UI,
783 GL_RG8,
784 GL_RG16F,
785 GL_RG32F,
786 GL_RG8UI,
787 GL_RGB8,
788 GL_SRGB8,
789 GL_RGB565,
790 GL_R11F_G11F_B10F,
791 GL_RGB9_E5,
792 GL_RGB16F,
793 GL_RGB32F,
794 GL_RGB8UI,
795 GL_RGBA8,
796 GL_SRGB8_ALPHA8,
797 GL_RGB5_A1,
798 GL_RGBA4,
799 GL_RGBA16F,
800 GL_RGBA32F,
801 GL_RGBA8UI,
802 };
803
777 // ES2 enums 804 // ES2 enums
778 static const GLenum kSupportedFormatsES2[] = { 805 static const GLenum kSupportedFormatsES2[] = {
779 GL_RGB, 806 GL_RGB,
780 GL_RGBA, 807 GL_RGBA,
781 GL_LUMINANCE_ALPHA, 808 GL_LUMINANCE_ALPHA,
782 GL_LUMINANCE, 809 GL_LUMINANCE,
783 GL_ALPHA, 810 GL_ALPHA,
784 }; 811 };
785 812
786 // Exposed by GL_ANGLE_depth_texture 813 // Exposed by GL_ANGLE_depth_texture
(...skipping 15 matching lines...) Expand all
802 GL_RG, 829 GL_RG,
803 GL_RG_INTEGER, 830 GL_RG_INTEGER,
804 GL_RGB, 831 GL_RGB,
805 GL_RGB_INTEGER, 832 GL_RGB_INTEGER,
806 GL_RGBA, 833 GL_RGBA,
807 GL_RGBA_INTEGER, 834 GL_RGBA_INTEGER,
808 GL_DEPTH_COMPONENT, 835 GL_DEPTH_COMPONENT,
809 GL_DEPTH_STENCIL, 836 GL_DEPTH_STENCIL,
810 }; 837 };
811 838
839 // ES3 enums supported by TexImageSource
840 static const GLenum kSupportedFormatsTexImageSourceES3[] = {
841 GL_RED,
842 GL_RED_INTEGER,
843 GL_RG,
844 GL_RG_INTEGER,
845 GL_RGB,
846 GL_RGB_INTEGER,
847 GL_RGBA,
848 GL_RGBA_INTEGER,
849 };
850
812 // ES2 enums 851 // ES2 enums
813 static const GLenum kSupportedTypesES2[] = { 852 static const GLenum kSupportedTypesES2[] = {
814 GL_UNSIGNED_BYTE, 853 GL_UNSIGNED_BYTE,
815 GL_UNSIGNED_SHORT_5_6_5, 854 GL_UNSIGNED_SHORT_5_6_5,
816 GL_UNSIGNED_SHORT_4_4_4_4, 855 GL_UNSIGNED_SHORT_4_4_4_4,
817 GL_UNSIGNED_SHORT_5_5_5_1, 856 GL_UNSIGNED_SHORT_5_5_5_1,
818 }; 857 };
819 858
820 // Exposed by GL_OES_texture_float 859 // Exposed by GL_OES_texture_float
821 static const GLenum kSupportedTypesOESTexFloat[] = { 860 static const GLenum kSupportedTypesOESTexFloat[] = {
(...skipping 21 matching lines...) Expand all
843 GL_INT, 882 GL_INT,
844 GL_HALF_FLOAT, 883 GL_HALF_FLOAT,
845 GL_FLOAT, 884 GL_FLOAT,
846 GL_UNSIGNED_INT_2_10_10_10_REV, 885 GL_UNSIGNED_INT_2_10_10_10_REV,
847 GL_UNSIGNED_INT_10F_11F_11F_REV, 886 GL_UNSIGNED_INT_10F_11F_11F_REV,
848 GL_UNSIGNED_INT_5_9_9_9_REV, 887 GL_UNSIGNED_INT_5_9_9_9_REV,
849 GL_UNSIGNED_INT_24_8, 888 GL_UNSIGNED_INT_24_8,
850 GL_FLOAT_32_UNSIGNED_INT_24_8_REV, 889 GL_FLOAT_32_UNSIGNED_INT_24_8_REV,
851 }; 890 };
852 891
892 // ES3 enums supported by TexImageSource
893 static const GLenum kSupportedTypesTexImageSourceES3[] = {
894 GL_UNSIGNED_SHORT,
895 GL_SHORT,
896 GL_UNSIGNED_INT,
897 GL_INT,
898 GL_HALF_FLOAT,
899 GL_FLOAT,
900 GL_UNSIGNED_INT_10F_11F_11F_REV,
901 };
902
853 bool isUnsignedIntegerFormat(GLenum internalformat) 903 bool isUnsignedIntegerFormat(GLenum internalformat)
854 { 904 {
855 switch (internalformat) { 905 switch (internalformat) {
856 case GL_R8UI: 906 case GL_R8UI:
857 case GL_R16UI: 907 case GL_R16UI:
858 case GL_R32UI: 908 case GL_R32UI:
859 case GL_RG8UI: 909 case GL_RG8UI:
860 case GL_RG16UI: 910 case GL_RG16UI:
861 case GL_RG32UI: 911 case GL_RG32UI:
862 case GL_RGB8UI: 912 case GL_RGB8UI:
(...skipping 3160 matching lines...) Expand 10 before | Expand all | Expand 10 after
4023 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, ima geExtractor.imageWidth(), imageExtractor.imageHeight(), 1, format, type, needCon version ? data.data() : imagePixelData); 4073 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, ima geExtractor.imageWidth(), imageExtractor.imageHeight(), 1, format, type, needCon version ? data.data() : imagePixelData);
4024 } 4074 }
4025 restoreUnpackParameters(); 4075 restoreUnpackParameters();
4026 } 4076 }
4027 4077
4028 bool WebGLRenderingContextBase::validateTexFunc(const char* functionName, TexIma geFunctionType functionType, TexFuncValidationSourceType sourceType, GLenum targ et, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei d epth, GLint border, GLenum format, GLenum type, GLint xoffset, GLint yoffset, GL int zoffset) 4078 bool WebGLRenderingContextBase::validateTexFunc(const char* functionName, TexIma geFunctionType functionType, TexFuncValidationSourceType sourceType, GLenum targ et, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei d epth, GLint border, GLenum format, GLenum type, GLint xoffset, GLint yoffset, GL int zoffset)
4029 { 4079 {
4030 if (!validateTexFuncLevel(functionName, target, level)) 4080 if (!validateTexFuncLevel(functionName, target, level))
4031 return false; 4081 return false;
4032 4082
4033 if (!validateTexFuncParameters(functionName, functionType, target, level, in ternalformat, width, height, depth, border, format, type)) 4083 if (!validateTexFuncParameters(functionName, functionType, sourceType, targe t, level, internalformat, width, height, depth, border, format, type))
4034 return false; 4084 return false;
4035 4085
4036 if (functionType == TexSubImage) { 4086 if (functionType == TexSubImage) {
4037 if (!validateSettableTexFormat(functionName, format)) 4087 if (!validateSettableTexFormat(functionName, format))
4038 return false; 4088 return false;
4039 if (!validateSize(functionName, xoffset, yoffset, zoffset)) 4089 if (!validateSize(functionName, xoffset, yoffset, zoffset))
4040 return false; 4090 return false;
4041 } else { 4091 } else {
4042 // For SourceArrayBufferView, function validateTexFuncData() would handl e whether to validate the SettableTexFormat 4092 // For SourceArrayBufferView, function validateTexFuncData() would handl e whether to validate the SettableTexFormat
4043 // by checking if the ArrayBufferView is null or not. 4093 // by checking if the ArrayBufferView is null or not.
(...skipping 1475 matching lines...) Expand 10 before | Expand all | Expand 10 after
5519 continue; 5569 continue;
5520 } 5570 }
5521 if (!validateCharacter(string[i])) { 5571 if (!validateCharacter(string[i])) {
5522 synthesizeGLError(GL_INVALID_VALUE, "shaderSource", "string not ASCI I"); 5572 synthesizeGLError(GL_INVALID_VALUE, "shaderSource", "string not ASCI I");
5523 return false; 5573 return false;
5524 } 5574 }
5525 } 5575 }
5526 return true; 5576 return true;
5527 } 5577 }
5528 5578
5529 bool WebGLRenderingContextBase::validateTexFuncFormatAndType(const char* functio nName, TexImageFunctionType functionType, GLenum internalformat, GLenum format, GLenum type, GLint level) 5579 bool WebGLRenderingContextBase::validateTexFuncFormatAndType(const char* functio nName, TexImageFunctionType functionType, TexFuncValidationSourceType sourceType , GLenum internalformat, GLenum format, GLenum type, GLint level)
5530 { 5580 {
5531 if (!m_isWebGL2FormatsTypesAdded && isWebGL2OrHigher()) { 5581 if (!m_isWebGL2FormatsTypesAdded && isWebGL2OrHigher()) {
5532 ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalFormatsE S3); 5582 if (sourceType == SourceHTMLImageElement || sourceType == SourceHTMLCanv asElement || sourceType == SourceHTMLVideoElement) {
qiankun 2016/09/26 14:34:11 I am not sure should SourceImageData and SourceIma
Ken Russell (switch to Gerrit) 2016/09/26 22:19:43 Yes, the same rules apply to all of the types in t
qiankun 2016/09/27 10:22:25 I added another function WebGLRenderingContextBase
5533 ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalFormatsT exImageES3); 5583 ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalForm atsTexImageSourceES3);
5534 ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsES3); 5584 ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsTexImageSourc eES3);
5535 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesES3); 5585 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesTexImageSourceES3 );
5586 } else {
5587 ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalForm atsES3);
5588 ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalForm atsTexImageES3);
5589 ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsES3);
5590 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesES3);
5591 }
5536 m_isWebGL2FormatsTypesAdded = true; 5592 m_isWebGL2FormatsTypesAdded = true;
5537 } 5593 }
5538 5594
5539 if (!isWebGL2OrHigher()) { 5595 if (!isWebGL2OrHigher()) {
5540 if (!m_isOESTextureFloatFormatsTypesAdded && extensionEnabled(OESTexture FloatName)) { 5596 if (!m_isOESTextureFloatFormatsTypesAdded && extensionEnabled(OESTexture FloatName)) {
5541 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesOESTexFloat); 5597 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesOESTexFloat);
5542 m_isOESTextureFloatFormatsTypesAdded = true; 5598 m_isOESTextureFloatFormatsTypesAdded = true;
5543 } 5599 }
5544 5600
5545 if (!m_isOESTextureHalfFloatFormatsTypesAdded && extensionEnabled(OESTex tureHalfFloatName)) { 5601 if (!m_isOESTextureHalfFloatFormatsTypesAdded && extensionEnabled(OESTex tureHalfFloatName)) {
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
5671 } 5727 }
5672 break; 5728 break;
5673 } 5729 }
5674 default: 5730 default:
5675 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid target"); 5731 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid target");
5676 return false; 5732 return false;
5677 } 5733 }
5678 return true; 5734 return true;
5679 } 5735 }
5680 5736
5681 bool WebGLRenderingContextBase::validateTexFuncParameters(const char* functionNa me, TexImageFunctionType functionType, GLenum target, 5737 bool WebGLRenderingContextBase::validateTexFuncParameters(const char* functionNa me, TexImageFunctionType functionType, TexFuncValidationSourceType sourceType, G Lenum target,
5682 GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei d epth, GLint border, GLenum format, GLenum type) 5738 GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei d epth, GLint border, GLenum format, GLenum type)
5683 { 5739 {
5684 // We absolutely have to validate the format and type combination. 5740 // We absolutely have to validate the format and type combination.
5685 // The texImage2D entry points taking HTMLImage, etc. will produce 5741 // The texImage2D entry points taking HTMLImage, etc. will produce
5686 // temporary data based on this combination, so it must be legal. 5742 // temporary data based on this combination, so it must be legal.
5687 if (!validateTexFuncFormatAndType(functionName, functionType, internalformat , format, type, level)) 5743 if (!validateTexFuncFormatAndType(functionName, functionType, sourceType, in ternalformat, format, type, level))
5688 return false; 5744 return false;
5689 5745
5690 if (!validateTexFuncDimensions(functionName, functionType, target, level, wi dth, height, depth)) 5746 if (!validateTexFuncDimensions(functionName, functionType, target, level, wi dth, height, depth))
5691 return false; 5747 return false;
5692 5748
5693 if (border) { 5749 if (border) {
5694 synthesizeGLError(GL_INVALID_VALUE, functionName, "border != 0"); 5750 synthesizeGLError(GL_INVALID_VALUE, functionName, "border != 0");
5695 return false; 5751 return false;
5696 } 5752 }
5697 5753
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after
6473 6529
6474 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas(HTMLCanvasElementOrOffs creenCanvas& result) const 6530 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas(HTMLCanvasElementOrOffs creenCanvas& result) const
6475 { 6531 {
6476 if (canvas()) 6532 if (canvas())
6477 result.setHTMLCanvasElement(canvas()); 6533 result.setHTMLCanvasElement(canvas());
6478 else 6534 else
6479 result.setOffscreenCanvas(getOffscreenCanvas()); 6535 result.setOffscreenCanvas(getOffscreenCanvas());
6480 } 6536 }
6481 6537
6482 } // namespace blink 6538 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698